MCP Create Server

Server Configuration

Describes the environment variables required to run the server.

NameRequiredDescriptionDefault

No arguments

Schema

Prompts

Interactive templates invoked by user choice

NameDescription

No prompts

Resources

Contextual data attached and managed by the client

NameDescription

No resources

Tools

Functions exposed to the LLM to take actions

NameDescription
create-server-from-template

Create a new MCP server from a template.

以下のテンプレートコードをベースに、ユーザーの要求に合わせたサーバーを実装してください。 言語に応じて適切なテンプレートを選択し、必要に応じて機能を追加・変更してください。

TypeScriptテンプレート:

import { Server } from "@modelcontextprotocol/sdk/server/index.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js"; const server = new Server({ name: "dynamic-test-server", version: "1.0.0" }, { capabilities: { tools: {} } }); // ここでツールを実装してください server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [{ name: "echo", description: "Echo back a message", inputSchema: { type: "object", properties: { message: { type: "string" } }, required: ["message"] } }] }; }); server.setRequestHandler(CallToolRequestSchema, async (request) => { if (request.params.name === "echo") { // TypeScriptの型を適切に扱うため、型アサーションを使用 const message = request.params.arguments.message as string; // または any を使う: const message: any = request.params.arguments.message; return { content: [ { type: "text", text: `Echo: ${message}` } ] }; } throw new Error("Tool not found"); }); // Server startup const transport = new StdioServerTransport(); server.connect(transport);

Pythonテンプレート:

import asyncio from mcp.server import Server from mcp.server.stdio import stdio_server app = Server("dynamic-test-server") @app.list_tools() async def list_tools(): return [ { "name": "echo", "description": "Echo back a message", "inputSchema": { "type": "object", "properties": { "message": {"type": "string"} }, "required": ["message"] } } ] @app.call_tool() async def call_tool(name, arguments): if name == "echo": return [{"type": "text", "text": f"Echo: {arguments.get('message')}"}] raise ValueError(f"Tool not found: {name}") async def main(): async with stdio_server() as streams: await app.run( streams[0], streams[1], app.create_initialization_options() ) if __name__ == "__main__": asyncio.run(main())

注意事項:

  • TypeScript実装時は、引数の型を適切に扱うために型アサーション(as string)を使用するか、 明示的に型を宣言してください(例:const value: string = request.params.arguments.someValue)。
  • 複雑な型を扱う場合は、interface や type を定義して型安全性を確保することをお勧めします。

ユーザーの要求に応じて上記のテンプレートを参考にカスタマイズしてください。その際、基本的な構造を維持しつつ、ツール名や機能を変更できます。

execute-tool

Execute a tool on a server

get-server-tools

Get the tools available on a server

delete-server

Delete a server

list-servers

List all running servers