
This project was created with create-xmcp-app.
First, run the development server:
npm run dev# oryarn dev# orpnpm devThis will start the MCP server with the selected transport method.
This project uses the structured approach where tools, prompts, and resources are automatically discovered from their respective directories:
src/tools - Tool definitionssrc/prompts - Prompt templatessrc/resources - Resource handlersEach tool is defined in its own file with the following structure:
import { z } from 'zod'import { type InferSchema, type ToolMetadata } from 'xmcp'
export const schema = { name: z.string().describe('The name of the user to greet'),}
export const metadata: ToolMetadata = { name: 'greet', description: 'Greet the user', annotations: { title: 'Greet the user', readOnlyHint: true, destructiveHint: false, idempotentHint: true, },}
export default function greet({ name }: InferSchema<typeof schema>) { return `Hello, ${name}!`}Prompts are template definitions for AI interactions:
import { z } from 'zod'import { type InferSchema, type PromptMetadata } from 'xmcp'
export const schema = { code: z.string().describe('The code to review'),}
export const metadata: PromptMetadata = { name: 'review-code', title: 'Review Code', description: 'Review code for best practices and potential issues', role: 'user',}
export default function reviewCode({ code }: InferSchema<typeof schema>) { return `Please review this code: ${code}`}Resources provide data or content with URI-based access:
import { z } from 'zod'import { type ResourceMetadata, type InferSchema } from 'xmcp'
export const schema = { userId: z.string().describe('The ID of the user'),}
export const metadata: ResourceMetadata = { name: 'user-profile', title: 'User Profile', description: 'User profile information',}
export default function handler({ userId }: InferSchema<typeof schema>) { return `Profile data for user ${userId}`}To add a new tool:
.ts file in the src/tools directoryschema object defining the tool parameters using Zodmetadata object with tool informationTo add a new prompt:
.ts file in the src/prompts directoryschema object defining the prompt parameters using Zodmetadata object with prompt information and roleTo add a new resource:
.ts file in the src/resources directory(users)/[userId]/profile.ts → users://{userId}/profile)schema object for dynamic parameters (optional for static resources)metadata object with resource informationTo build your project for production:
pnpm buildThis will compile your TypeScript code and output it to the dist directory.
You can run the server for the transport built with:
node dist/http.jsnode dist/stdio.jsGiven the selected transport method, you will have a custom start script added to the package.json file.
For HTTP:
pnpm start-httpFor STDIO:
pnpm start-stdio