@suiware/mcp
Version:
An stdio MCP server with built-in Suiware AI Tools.
1 lines • 4.29 kB
Source Map (JSON)
{"version":3,"sources":["../src/utils/mappers.ts","../src/index.ts"],"names":["mapZodSchemaToMCPSchema","schema","shape","mcpSchema","key","value","ZodOptional","mapVercelToolToMcpTool","tool","params","result","error","startSuiwareMcpServer","options","server","createSuiwareMcpServer","transport","StdioServerTransport","McpServer","name","getSuiwareAiTools","mcpTool"],"mappings":"6NAIA,IAAMA,CAAAA,CAA2BC,GAAqC,CACpE,IAAMC,CAAQD,CAAAA,CAAAA,CAAO,MAEfE,CAAwC,CAAA,GAE9C,IAAW,GAAA,CAACC,EAAKC,CAAK,CAAA,GAAK,OAAO,OAAQH,CAAAA,CAAK,EAC7CC,CAAUC,CAAAA,CAAG,EACXH,CAAkBK,YAAAA,WAAAA,CAAeD,EAAc,MAAO,EAAA,CAAIA,CAG9D,CAAA,OAAOF,CACT,CAEaI,CAAAA,CAAAA,CAA0BC,IAC9B,CACL,WAAA,CAAaA,EAAK,WAClB,CAAA,YAAA,CAAcR,EAAwBQ,CAAK,CAAA,UAAU,EACrD,EAAI,CAAA,MAAOC,GAAW,CACpB,GAAI,CAEF,IAAIC,CAAAA,CACJ,OAAIF,CAAAA,CAAK,mBAAmB,QAC1BE,GAAAA,CAAAA,CAAS,MAAMF,CAAK,CAAA,OAAA,CAAQC,EAAe,EAAS,GAG/C,CACL,OAAA,CAAS,CACP,CACE,IAAA,CAAM,OACN,IAAM,CAAA,IAAA,CAAK,UAAUC,CAAQ,CAAA,IAAA,CAAM,CAAC,CACtC,CACF,CACF,CACF,OAASC,CAAO,CAAA,CACd,eAAQ,KAAM,CAAA,OAAA,CAASA,CAAK,CACrB,CAAA,CACL,QAAS,IACT,CAAA,OAAA,CAAS,CACP,CACE,IAAA,CAAM,OACN,IACEA,CAAAA,CAAAA,YAAiB,KACbA,CAAAA,CAAAA,CAAM,QACN,wBACR,CACF,CACF,CACF,CACF,CACF,CC7CK,CAAA,CAAA,IAAMC,EAAwB,MACnCC,CAAAA,EACuB,CACvB,IAAMC,CAAAA,CAASC,EAAuBF,CAAO,CAAA,CACvCG,EAAY,IAAIC,oBAAAA,CAEtB,OAAMH,MAAAA,CAAAA,CAAO,QAAQE,CAAS,CAAA,CAEvBF,CACT,CAEMC,CAAAA,CAAAA,CACJF,GACc,CACd,IAAMC,EAAS,IAAII,SAAAA,CAAUL,CAAO,CAEpC,CAAA,IAAA,GAAW,CAACM,CAAMX,CAAAA,CAAI,IAAK,MAAO,CAAA,OAAA,CAAQY,iBAAkB,EAAC,EAAG,CAE9D,IAAMC,EAAUd,CAAuBC,CAAAA,CAAI,EAC3CM,CAAO,CAAA,IAAA,CAAKK,EAAME,CAAQ,CAAA,WAAA,CAAaA,EAAQ,YAAcA,CAAAA,CAAAA,CAAQ,EAAE,EACzE,CAEA,OAAOP,CACT","file":"index.mjs","sourcesContent":["import { Tool } from 'ai'\nimport { ZodOptional, ZodRawShape, ZodTypeAny } from 'zod'\nimport { McpTool } from '../types/McpTool'\n\nconst mapZodSchemaToMCPSchema = (schema: ZodRawShape): ZodRawShape => {\n const shape = schema.shape\n\n const mcpSchema: Record<string, ZodTypeAny> = {}\n\n for (const [key, value] of Object.entries(shape)) {\n mcpSchema[key] =\n schema instanceof ZodOptional ? (value as any).unwrap() : value\n }\n\n return mcpSchema\n}\n\nexport const mapVercelToolToMcpTool = (tool: Tool): McpTool => {\n return {\n description: tool.description!,\n paramsSchema: mapZodSchemaToMCPSchema(tool.parameters),\n cb: async (params) => {\n try {\n // @todo: Improve parameter types.\n let result\n if (tool.execute instanceof Function) {\n result = await tool.execute(params as any, {} as any)\n }\n\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(result, null, 2),\n },\n ],\n }\n } catch (error) {\n console.error('error', error)\n return {\n isError: true,\n content: [\n {\n type: 'text',\n text:\n error instanceof Error\n ? error.message\n : 'Unknown error occurred',\n },\n ],\n }\n }\n },\n }\n}\n","import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'\nimport { Implementation } from '@modelcontextprotocol/sdk/types.js'\nimport { getSuiwareAiTools } from '@suiware/ai-tools'\nimport { mapVercelToolToMcpTool } from './utils/mappers'\n\nexport interface SuiwareMcpServerOptions extends Implementation {}\n\nexport const startSuiwareMcpServer = async (\n options: SuiwareMcpServerOptions\n): Promise<McpServer> => {\n const server = createSuiwareMcpServer(options)\n const transport = new StdioServerTransport()\n\n await server.connect(transport)\n\n return server\n}\n\nconst createSuiwareMcpServer = (\n options: SuiwareMcpServerOptions\n): McpServer => {\n const server = new McpServer(options)\n\n for (const [name, tool] of Object.entries(getSuiwareAiTools())) {\n // Hope we will have a native Tool type soon https://github.com/modelcontextprotocol/typescript-sdk/issues/369\n const mcpTool = mapVercelToolToMcpTool(tool)\n server.tool(name, mcpTool.description, mcpTool.paramsSchema, mcpTool.cb)\n }\n\n return server\n}\n"]}