Declarative MCP Server – README | MCP Marketplace

✨ From vibe coding to vibe deployment. UBOS MCP turns ideas into infra with one message.

Learn more

MCP Declarative Server

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

Installation

npm install mcp-client-router

Usage

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 Reference

DeclarativeMCPServer

new DeclarativeMCPServer(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

Featured Templates

View More
Verified Icon
AI Agents
AI Chatbot Starter Kit
1308 6081 5.0
Data Analysis
Pharmacy Admin Panel
238 1704
AI Assistants
Talk with Claude 3
156 1165
AI Assistants
AI Chatbot Starter Kit v0.1
130 667
AI Characters
Sarcastic AI Chat Bot
128 1440

Start your free trial

Build your solution today. No credit card required.

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.