Last active
April 12, 2025 07:47
-
-
Save kuc-arc-f/ab056e657e97134006d66cc158d2e68b to your computer and use it in GitHub Desktop.
mcp_example_1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"mcpServers": { | |
"mcp-2ex": { | |
"command": "node", | |
"args": [ | |
"/path123/mcp/mcp-2ex/build/index.js" | |
], | |
"env": { | |
"API_URL": "http://localhost:8787", | |
"API_KEY": "123" | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; | |
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; | |
import { z } from "zod"; | |
const server = new McpServer({ | |
name: "mcp-2ex", | |
version: "1.0.0", | |
}); | |
server.tool( | |
"mcp-2ex-test", | |
"与えられた文字列を登録する。", | |
{text: z.string().min(1, { message: 'タイトルは必須です' })}, | |
async ({text}) => { | |
try{ | |
const url = process.env.API_URL; | |
const item = {title: text, description:"" } | |
const response = await fetch(url + "/api/todos/create" , | |
{ | |
method: "POST", | |
headers: { "Content-Type": "application/json" }, | |
body: JSON.stringify(item), | |
} | |
); | |
if(response.ok === false){ | |
throw new Error("Error, response <> OK:"); | |
} | |
const body = await response.text(); | |
return {content: [{type: "text", text: body}]}; | |
}catch(e){ | |
throw new Error("Error, mcp-2ex-test:" + e); | |
} | |
}, | |
); | |
async function main() { | |
const transport = new StdioServerTransport(); | |
await server.connect(transport); | |
console.error("Example MCP Server running on stdio"); | |
} | |
main().catch((error) => { | |
console.error("Fatal error in main():", error); | |
process.exit(1); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "mcp-2ex", | |
"version": "1.0.0", | |
"main": "index.js", | |
"type": "module", | |
"bin": { | |
"mcp-example": "./build/index.js" | |
}, | |
"scripts": { | |
"build": "tsc", | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"description": "", | |
"files": [ | |
"build" | |
], | |
"dependencies": { | |
"@modelcontextprotocol/sdk": "^1.9.0", | |
"zod": "^3.24.2" | |
}, | |
"devDependencies": { | |
"@types/node": "^22.14.0", | |
"typescript": "^5.8.3" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"compilerOptions": { | |
"target": "ES2022", | |
"module": "Node16", | |
"moduleResolution": "Node16", | |
"outDir": "./build", | |
"rootDir": "./src", | |
"strict": true, | |
"esModuleInterop": true, | |
"skipLibCheck": true, | |
"forceConsistentCasingInFileNames": true | |
}, | |
"include": ["src/**/*"], | |
"exclude": ["node_modules"] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment