xmcp: Model Context Protocol Framework

0.6.7 · active · verified Sun Apr 19

xmcp is a TypeScript-first framework designed for building and deploying Model Context Protocol (MCP) servers. It aims to simplify the development experience for creating powerful tools within the MCP ecosystem, providing features like file system routing for automatic tool and prompt registration, hot reloading for rapid development, and a robust middleware system for authentication and custom logic. Currently at version 0.6.7, the project maintains an active development pace with frequent minor and patch releases (often weekly or bi-weekly), incorporating new features, security updates, and performance improvements. Key differentiators include its focus on developer experience, support for various deployment targets like Vercel and Cloudflare, and an 'elicit' mechanism within tool handlers for requesting structured user input.

Common errors

Warnings

Install

Imports

Quickstart

Initializes an xmcp project and demonstrates defining a tool that uses the `extra.elicit` function to prompt the user for structured input before proceeding with a simulated deployment.

// First, initialize a new xmcp project:
// npx create-xmcp-app@latest my-xmcp-app
// cd my-xmcp-app

// Then, create a tool file within your project, for example, at src/tools/deploy.ts.
// xmcp automatically registers tools based on file system routing.

import { type ToolHandlerContext } from 'xmcp';

export default async function (
  _args: Record<string, any>, // Arguments received by the tool
  extra: ToolHandlerContext  // Context object providing utilities
) {
  console.log("Deployment tool invoked. Awaiting user input...");

  const result = await extra.elicit({
    message: "Please choose deployment parameters:",
    requestedSchema: {
      type: "object",
      properties: {
        environment: {
          type: "string",
          title: "Deployment Environment",
          enum: ["staging", "production"],
          description: "Target environment for deployment."
        },
        confirmAction: {
          type: "boolean",
          title: "Confirm Deployment",
          description: "Are you sure you want to proceed with deployment?",
          default: false
        }
      },
      required: ["environment", "confirmAction"],
    },
  });

  if (result.action !== "accept" || !result.content || !result.content.confirmAction) {
    return "Deployment action cancelled or not confirmed by the user.";
  }

  const { environment } = result.content;
  console.log(`Initiating deployment to ${environment}...`);
  // In a real application, replace this with actual deployment logic
  await new Promise(resolve => setTimeout(resolve, 3000)); // Simulate work

  return `Deployment to ${environment} completed successfully!`;
}

// To run this tool, start your xmcp development server (e.g., `npm run dev`).
// Then, interact with your MCP server via a compatible client or interface
// to invoke the 'deploy' tool, which will trigger the elicitation flow.

view raw JSON →