AT-360 Added Diagram Chat Functionality To Mermaid/sdk So MCP Server Can Directly Access Mermaid AI #43
Conversation
…at with mermaid ai
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
There was a problem hiding this comment.
Pull request overview
Adds SDK support for a new Mermaid AI “diagram chat” endpoint so consumers (e.g., an MCP server) can send a user prompt + optional diagram context and receive streamed AI output.
Changes:
- Added
/rest-api/openai/chatURL constant. - Introduced
DiagramChatRequest/DiagramChatResponsepublic types. - Implemented
MermaidChart.diagramChat()including parsing of Vercel AI SDK data-stream output.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| packages/sdk/src/urls.ts | Adds the REST URL for the new OpenAI chat endpoint. |
| packages/sdk/src/types.ts | Defines request/response types for diagram chat. |
| packages/sdk/src/index.ts | Implements diagramChat() and helpers to parse the streamed response body. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
packages/sdk/src/index.ts:24
- The PR description says the new DiagramChatRequest/DiagramChatResponse types are exposed for SDK consumers, but the entrypoint doesn’t re-export them. Since this package’s public surface is
src/index.ts(anddist/index.d.ts), consider adding explicitexport type { DiagramChatRequest, DiagramChatResponse } from './types.js'so consumers can import them from@mermaidchart/sdkwithout deep imports.
import type {
AuthState,
AuthorizationData,
DiagramChatRequest,
DiagramChatResponse,
Document,
InitParams,
MCDocument,
MCProject,
MCUser,
RepairDiagramRequest,
RepairDiagramResponse,
AICreditsUsage,
} from './types.js';
import { URLS } from './urls.js';
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** | ||
| * The document ID used for this conversation. Same as the one passed in the request. | ||
| */ | ||
| documentID?: string; |
There was a problem hiding this comment.
DiagramChatResponse.documentID is marked optional, but MermaidChart.diagramChat() always returns documentID and the request requires it. Making this required (or omitting it entirely from the response type) would avoid confusing consumers and better reflect the actual behavior.
| documentID?: string; | |
| documentID: string; |
| vi.spyOn(client, 'diagramChat').mockRejectedValue( | ||
| new AICreditsLimitExceededError('AI credits limit exceeded'), | ||
| ); |
There was a problem hiding this comment.
This test doesn’t exercise the 402-handling logic in diagramChat() because it mocks client.diagramChat() itself to reject. Instead, mock the underlying axios .post() to reject with a { response: { status: 402, data: ... } } shape and assert that diagramChat() maps it to AICreditsLimitExceededError.
| vi.spyOn(client, 'diagramChat').mockRejectedValue( | |
| new AICreditsLimitExceededError('AI credits limit exceeded'), | |
| ); | |
| // Mock the underlying axios call to simulate a 402 response from the API. | |
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | |
| vi.spyOn((client as any).axios, 'post').mockRejectedValue({ | |
| response: { | |
| status: 402, | |
| data: { | |
| message: 'AI credits limit exceeded', | |
| }, | |
| }, | |
| }); |
This pull request adds a diagramChat method to the @mermaidchart/sdk, enabling external clients such as MCP servers to chat directly with Mermaid AI without handling streaming internals themselves.
These changes also expose the necessary types (DiagramChatRequest, DiagramChatResponse) so consumers get full TypeScript support for the new chat capability.
New diagramChat method in SDK: