Skip to main content
Glama
johnhenry

MCP Declarative Server

by johnhenry

MCP Declarative Server

A utility module for creating Model Context Protocol (MCP) servers declaratively.

Installation

npm install mcp-client-router

Related MCP server: YA_MCPServer Template

Usage

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);

API Reference

MCPDeclarativeServer

new MCPDeclarativeServer(options);

Options

  • name (string): The name of the server

  • version (string): The version of the server

  • tools (array): An array of tool definitions

  • prompts (array): An array of prompt definitions

  • resources (array): An array of resource definitions

Tool Definition Format

[
  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
];

Prompt Definition Format

[
  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
];

Resource Definition Format

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

License

ISC

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    A command-line tool for creating and running Model Context Protocol servers that expose resources, tools, and prompts to LLM clients.
    94 npm
    1
    AGPL 3.0
  • F
    license
    Not graded
    quality
    D
    maintenance
    A boilerplate template for developing Model Context Protocol (MCP) servers, providing a structured framework for defining tools, resources, and prompts.
    -
  • A
    license
    Not graded
    quality
    A
    maintenance
    Embeds a secure, curated MCP server inside Python applications, exposing explicit tools, resources, and prompts with dependency injection, security policies, and in-memory testing.
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables developers to build and deploy secure, typed Model Context Protocol servers with tools, resources, prompts, bearer-token authentication, per-tool scopes, rate limiting, and health probes over Streamable HTTP.
    MIT