MCP 선언적 서버
선언적으로 MCP(Model Context Protocol) 서버를 생성하기 위한 유틸리티 모듈입니다.
설치
지엑스피1
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
];
특허
아이에스씨