A Model Context Protocol (MCP) server built on Cloudflare Workers with TypeScript, supporting Streamable HTTP transport protocol.
- 🚀 Serverless architecture on Cloudflare Workers
- 📡 Latest MCP Streamable HTTP transport protocol support
- 🛠️ Extensible tools framework
- 📝 Extensible prompts framework
- 🔧 TypeScript type safety
- 🌐 CORS support
- 💡 Simple project structure, easy to extend
diagramly-mcp-serverless/
├── src/
│ ├── index.ts # Main Worker entry point
│ ├── tools/
│ │ ├── index.ts # Tools registry and manager
│ │ └── mermaid-to-image.ts # Mermaid diagram to image tool
│ └── prompts/
│ ├── index.ts # Prompts registry and manager
│ └── mermaid-flowchart.ts # Mermaid flowchart prompt
├── package.json # Project dependencies
├── tsconfig.json # TypeScript configuration
├── wrangler.jsonc # Cloudflare Worker configuration
└── README.md # Project documentation
npx wrangler devThis will start the local development server, typically at http://localhost:8787
npx wrangler deploynpm run type-checkPOST /mcp- MCP protocol communication endpointGET /health- Health check endpointOPTIONS /*- CORS preflight request handling
Currently includes:
- mermaid-to-image: Convert Mermaid diagrams to images
- Parameters:
diagramCode(string),imageType(optional: "png" | "svg") - Function: Converts Mermaid diagram code to PNG or SVG images using Kroki service
- Parameters:
Currently includes:
- mermaid-flowchart: Convert content to Mermaid flowchart
- Parameters:
content(string) - Function: Generates prompts to convert user content into Mermaid flowchart diagrams
- Parameters:
- Create a new tool file in
src/tools/ - Define your tool following the
ToolDefinitioninterface - Add it to the
toolRegistryinsrc/tools/index.ts
Example:
export const myNewTool: ToolDefinition = {
name: "my-new-tool",
description: "Description of what this tool does",
inputSchema: {
param1: z.string(),
param2: z.number().optional()
},
handler: async ({ param1, param2 }) => {
// Tool implementation logic
return {
content: [{
type: "text",
text: "Tool result"
}]
};
}
};- Create a new prompt file in
src/prompts/ - Define your prompt following the
PromptDefinitioninterface - Add it to the
promptRegistryinsrc/prompts/index.ts
Example:
export const myNewPrompt: PromptDefinition = {
name: "my-new-prompt",
config: {
title: "My New Prompt",
description: "Description of what this prompt does",
argsSchema: { content: z.string() }
},
handler: ({ content }) => ({
messages: [{
role: "user",
content: {
type: "text",
text: `Your prompt template here: ${content}`
}
}]
})
};- @modelcontextprotocol/sdk: MCP framework core
- agents: MCP agent library
- hono: Web framework for Cloudflare Workers
- zod: Data validation library
- pako: Compression library for Mermaid diagrams
MIT License