Skip to main content
Glama
johnhenry

MCP Declarative Server

by johnhenry

MCP 声明式服务器

用于声明式创建模型上下文协议 (MCP) 服务器的实用程序模块。

安装

npm install mcp-client-router

Related MCP server: MCP Server Starter

用法

import { DeclarativeMCPServer } from "mcp-client-router/declarative-server"; // Create a server declaratively const server = new DeclarativeMCPServer({ name: "my-server", version: "1.0.0", // Define tools as arrays of arguments tools: [ [ "greeting", { message: "string" }, async ({ message }) => ({ content: [{ type: "text", text: `Hello, ${message}!` }], }), ], [ "farewell", { name: "string" }, async ({ name }) => ({ content: [{ type: "text", text: `Goodbye, ${name}!` }], }), ], ], // Define prompts prompts: [ [ "welcome", { name: "string", formality: { type: "string", default: "CASUAL" } }, async ({ name, formality }) => { const text = formality === "FORMAL" ? `Dear ${name}, welcome to our service.` : `Hi ${name}! Welcome aboard!`; return { messages: [{ role: "assistant", content: { text } }], }; }, "A welcome prompt template", ], ], // Define resources resources: [ [ "docs/readme", async () => ({ contents: [ { uri: "docs/readme", text: "This is the documentation readme file.", }, ], }), ], ], }); // Connect to a transport await server.connect(transport);

API 参考

DeclarativeMCPServer

new DeclarativeMCPServer(options);

选项

  • name (字符串):服务器的名称

  • version (字符串):服务器的版本

  • tools (数组):工具定义数组

  • prompts (数组):提示定义数组

  • resources (数组):资源定义数组

工具定义格式

[ name, // string: name of the tool paramSchema, // object: parameter schema handler, // function: async function to handle the tool call description, // string (optional): description of the tool ];

提示定义格式

[ name, // string: name of the prompt paramSchema, // object: parameter schema handler, // function: async function to handle the prompt description, // string (optional): description of the prompt ];

资源定义格式

[ uri, // string: URI of the resource handler, // function: async function to handle the resource request ];

执照

国际学习中心

-
security - not tested
F
license - not found
-
quality - not tested

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/johnhenry/mcp-declarative-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server