UNPKG

tokyo-metro-mcp-server

Version:
118 lines (96 loc) 2.29 kB
# Tokyo Metro MCP Server - Mastra Integration ## Option 1: Direct Node Execution (Recommended) Use absolute paths since `cwd` is not supported: ```typescript import { MCPClient } from "@mastra/mcp"; const mcp = new MCPClient({ servers: { postgres: { command: "npx", args: [ "-y", "@modelcontextprotocol/server-postgres", "postgres://postgres:postgres@localhost:5432/employee", ], }, tokyoMetro: { command: "node", args: ["/home/ta/tokyo-metro/dist/index.js"], env: { MODE: "stdio", }, }, }, }); ``` ## Option 2: Global Installation First install the server globally and add bin script: Add to package.json: ```json { "bin": { "tokyo-metro-mcp": "./dist/index.js" } } ``` Then: ```bash cd /home/ta/tokyo-metro npm run build npm link ``` Use in Mastra: ```typescript const mcp = new MCPClient({ servers: { tokyoMetro: { command: "tokyo-metro-mcp", args: [], }, }, }); ``` ## Option 3: NPX with GitHub Publish to npm or use npx with absolute path: ```typescript const mcp = new MCPClient({ servers: { tokyoMetro: { command: "npx", args: ["-y", "/home/ta/tokyo-metro"], }, }, }); ``` ## Usage Example ```typescript import { MCPClient } from "@mastra/mcp"; import { Agent } from "@mastra/core/agent"; import { openai } from "@ai-sdk/openai"; const mcp = new MCPClient({ servers: { tokyoMetro: { command: "npm", args: ["start"], cwd: "/home/ta/tokyo-metro", env: { MODE: "stdio" }, }, }, }); const agent = new Agent({ name: "Tokyo Metro Assistant", instructions: "You can access Tokyo Metro data including COVID-19 statistics and general API queries.", model: openai("gpt-4"), tools: await mcp.getTools(), }); // Test the integration const response = await agent.generate( "Get COVID-19 data for Tokyo from January 2021 to March 2021" ); console.log(response.text); ``` ## Available Tools Once integrated, you'll have access to these tools: - `tokyoMetro_tokyo_metro_query` - Query any Tokyo Metro API endpoint - `tokyoMetro_get_sample_covid_data` - Get COVID-19 data with date filtering The subprocess approach is more reliable than HTTP/SSE for MCP integration with Mastra.