Declaratively create and manage Model Context Protocol servers with customizable tools, prompts, and resources for streamlined asynchronous handling and integration.
Unlock the full potential of MCP Declarative Server through LangDB's AI Gateway. Get enterprise-grade security, analytics, and seamless integration with zero configuration.
Free tier available • No credit card required
A utility module for creating Model Context Protocol (MCP) servers declaratively.
npm install mcp-client-router
import { MCPDeclarativeServer } from "mcp-client-router/declarative-server"; // Create a server declaratively const server = new MCPDeclarativeServer({ 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);
MCPDeclarativeServer
new MCPDeclarativeServer(options);
name
(string): The name of the serverversion
(string): The version of the servertools
(array): An array of tool definitionsprompts
(array): An array of prompt definitionsresources
(array): An array of resource definitions[ 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 ];
ISC
Discover shared experiences
Shared threads will appear here, showcasing real-world applications and insights from the community. Check back soon for updates!