### Install tmcp Core Package Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/docs/src/content/000-getting-started.md Installs the core tmcp package using various package managers. This is the first step in setting up a tmcp project. ```bash pnpm add tmcp ``` ```bash npm i tmcp ``` ```bash yarn add tmcp ``` ```bash bun add tmcp ``` -------------------------------- ### tmcp Project Creation CLI Wizard Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/docs/src/content/000-getting-started.md This code represents the interactive command-line interface (CLI) wizard for creating a tmcp project. It guides the user through project setup, including location, schema adapter, transport, authentication, example server, and dependency installation. ```bash ┌ 🚀 Welcome to create-tmcp! │ ◇ Where should we create your TMCP project? │ my-awesome-mcp │ ◇ Which schema adapter would you like to use? │ Valibot (Recommended) │ ◇ Which transports would you like to include? │ STDIO, HTTP │ ◇ Would you like to include OAuth 2.1 authentication? │ Yes │ ◇ Would you like to include an example MCP server? │ Yes │ ◇ Where should we place the example server? │ src/index.js │ ◇ Would you like to automatically install dependencies? │ Yes │ ◇ Which package manager would you like to use? │ pnpm (Recommended) │ ◇ Project created successfully! │ ◇ Next steps: ───────╮ │ │ │ cd my-awesome-mcp │ │ pnpm run dev │ │ │ ├─────────────────────╯ │ └ Happy coding! 🎉 ``` -------------------------------- ### Install TMCP Authentication Package Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/docs/src/content/000-getting-started.md Installs the @tmcp/auth package, which provides authentication helpers for MCP servers. This package is essential if you plan to use authentication and act as an Authorization server. ```bash pnpm add @tmcp/auth ``` ```bash npm i @tmcp/auth ``` ```bash yarn add @tmcp/auth ``` ```bash bun add @tmcp/auth ``` -------------------------------- ### Create tmcp Project using Package Managers Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/docs/src/content/000-getting-started.md This snippet demonstrates how to initiate a new tmcp project using different package managers. It requires the respective package manager (pnpm, npm, yarn, or bun) to be installed on your system. ```bash pnpm create tmcp ``` ```bash npm init tmcp ``` ```bash yarn create tmcp ``` ```bash bun create tmcp ``` -------------------------------- ### Install tmcp Validation Adapters Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/docs/src/content/000-getting-started.md Installs tmcp adapters for different validation libraries. Choose the adapter corresponding to your selected validation library. These adapters convert validation schemas to the JSON schema format required by the MCP protocol. ```bash pnpm add valibot @tmcp/adapter-valibot ``` ```bash npm i valibot @tmcp/adapter-valibot ``` ```bash yarn add valibot @tmcp/adapter-valibot ``` ```bash bun add valibot @tmcp/adapter-valibot ``` ```bash pnpm add zod @tmcp/adapter-zod ``` ```bash npm i zod @tmcp/adapter-zod ``` ```bash yarn add zod @tmcp/adapter-zod ``` ```bash bun add zod @tmcp/adapter-zod ``` ```bash pnpm add zod @tmcp/adapter-zod-v3 ``` ```bash npm i zod @tmcp/adapter-zod-v3 ``` ```bash yarn add zod @tmcp/adapter-zod-v3 ``` ```bash bun add zod @tmcp/adapter-zod-v3 ``` ```bash pnpm add arktype @tmcp/adapter-arktype ``` ```bash npm i arktype @tmcp/adapter-arktype ``` ```bash yarn add arktype @tmcp/adapter-arktype ``` ```bash bun add arktype @tmcp/adapter-arktype ``` ```bash pnpm add effect-ts @tmcp/adapter-effect ``` ```bash npm i effect-ts @tmcp/adapter-effect ``` ```bash yarn add effect-ts @tmcp/adapter-effect ``` ```bash bun add effect-ts @tmcp/adapter-effect ``` -------------------------------- ### Install and Run TMCP Server (Bash) Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/create-tmcp/templates/README.md Commands to install dependencies, start the TMCP server, and run it with file watching for development. These are standard npm/pnpm commands. ```bash pnpm install pnpm run start pnpm run dev ``` -------------------------------- ### Install tmcp Transport Adapters Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/docs/src/content/000-getting-started.md Installs tmcp transport adapters for different communication protocols. Choose the adapter that matches your desired communication method: STDIO for local servers, HTTP for remote servers, or SSE (deprecated) for remote servers. ```bash pnpm add @tmcp/transport-stdio ``` ```bash npm i @tmcp/transport-stdio ``` ```bash yarn add @tmcp/transport-stdio ``` ```bash bun add @tmcp/transport-stdio ``` ```bash pnpm add @tmcp/transport-http ``` ```bash npm i @tmcp/transport-http ``` ```bash yarn add @tmcp/transport-http ``` ```bash bun add @tmcp/transport-http ``` ```bash pnpm add @tmcp/transport-sse ``` ```bash npm i @tmcp/transport-sse ``` ```bash yarn add @tmcp/transport-sse ``` ```bash bun add @tmcp/transport-sse ``` -------------------------------- ### Quick Start: HTTP Transport (Web-based) Source: https://github.com/paoloricciuti/tmcp/blob/main/README.md Illustrates how to set up a tmcp server for web-based clients using the HTTP transport. This example shows the server configuration, tool definition, and integration with a web server (Bun) to handle incoming requests via the transport. ```javascript import { McpServer } from 'tmcp'; import { ZodJsonSchemaAdapter } from '@tmcp/adapter-zod'; import { HttpTransport } from '@tmcp/transport-http'; import { z } from 'zod'; const adapter = new ZodJsonSchemaAdapter(); const server = new McpServer(/* ... same server config ... */); // Add tools as above... // Create HTTP transport const transport = new HttpTransport(server); // Use with your preferred HTTP server (Bun example) Bun.serve({ port: 3000, await fetch(req) { const response = await transport.respond(req); if (response === null) { return new Response('Not Found', { status: 404 }); } return response; }, }); ``` -------------------------------- ### Quick Start: Use SimpleProvider for Development Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/auth/README.md Illustrates the use of SimpleProvider from @tmcp/auth for a streamlined OAuth setup during development. It configures a client and its handlers with minimal boilerplate code, suitable for quick testing and prototyping. ```javascript // Or use SimpleProvider for quick development const simpleAuth = OAuth.issuer('https://auth.example.com') .clients( SimpleProvider.withClient('demo-client', 'demo-secret', [ 'https://app.example.com/callback', ]).clientStore, ) .handlers( SimpleProvider.withClient('demo-client', 'demo-secret', [ 'https://app.example.com/callback', ]).handlers(), ) .cors(true) .build(); ``` -------------------------------- ### Start Bun Server for TMCP Requests (TypeScript) Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/docs/src/routes/(landing)/example-2.md This code snippet shows how to start a Bun server that integrates with the TMCP transport layer. The server's fetch handler first attempts to respond to requests using the configured transport. If the transport cannot handle the request, it falls back to rendering the website. This requires the 'transport' object to be previously initialized. ```typescript Bun.serve({ async fetch(request) { return (await transport.respond(request)) ?? render_website(request); }, }); ``` -------------------------------- ### Example TMCP Project Workflow Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/create-tmcp/README.md This bash script outlines a typical workflow for creating and running a new TMCP project. It includes creating the project, selecting options interactively, installing dependencies, and starting the development server. ```bash # Create new project npx @tmcp/create-tmcp my-mcp-server # Follow interactive prompts: # ✓ Select Valibot adapter # ✓ Choose STDIO + HTTP transports # ✓ Include OAuth authentication # ✓ Generate example server # Start development cd my-mcp-server pnpm install pnpm run dev ``` -------------------------------- ### Install tmcp and Dependencies Source: https://github.com/paoloricciuti/tmcp/blob/main/README.md Installs the tmcp package along with a schema library adapter (e.g., Zod) and a transport mechanism (e.g., stdio or http). This setup is necessary before using tmcp in your project. ```bash pnpm install tmcp # Choose your preferred schema library adapter pnpm install @tmcp/adapter-zod zod # Choose your preferred transport pnpm install @tmcp/transport-stdio # For CLI/desktop apps pnpm install @tmcp/transport-http # For web-based clients ``` -------------------------------- ### Quick Start: Standard I/O Transport (CLI/Desktop) Source: https://github.com/paoloricciuti/tmcp/blob/main/README.md Demonstrates how to set up a tmcp server for CLI or desktop applications using the Standard I/O transport. It includes initializing the server with a Zod adapter, defining a tool with a type-safe schema, and starting the server with stdio transport. ```javascript import { McpServer } from 'tmcp'; import { ZodJsonSchemaAdapter } from '@tmcp/adapter-zod'; import { StdioTransport } from '@tmcp/transport-stdio'; import { z } from 'zod'; const adapter = new ZodJsonSchemaAdapter(); const server = new McpServer( { name: 'my-server', version: '1.0.0', description: 'My awesome MCP server', }, { adapter, capabilities: { tools: { listChanged: true }, prompts: { listChanged: true }, resources: { listChanged: true }, }, }, ); // While the adapter is optional (you can opt out by explicitly passing `adapter: undefined`) without an adapter the server cannot accept inputs, produce structured outputs, or request elicitations at all only do this for very simple servers. // Define a tool with type-safe schema server.tool( { name: 'calculate', description: 'Perform mathematical calculations', schema: z.object({ operation: z.enum(['add', 'subtract', 'multiply', 'divide']), a: z.number(), b: z.number(), }), }, async ({ operation, a, b }) => { switch (operation) { case 'add': return a + b; case 'subtract': return a - b; case 'multiply': return a * b; case 'divide': return a / b; } }, ); // Start the server with stdio transport const transport = new StdioTransport(server); transport.listen(); ``` -------------------------------- ### Basic TMCP Server with Stdio Transport Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/transport-stdio/README.md Demonstrates how to create a basic TMCP server and integrate it with the StdioTransport. This example shows server initialization, adding a tool, and starting the transport to listen on stdio. ```javascript import { McpServer } from 'tmcp'; import { StdioTransport } from '@tmcp/transport-stdio'; // Create your MCP server const server = new McpServer( { name: 'my-server', version: '1.0.0', description: 'My MCP server', }, { adapter: new YourSchemaAdapter(), capabilities: { tools: { listChanged: true }, prompts: { listChanged: true }, resources: { listChanged: true }, }, }, ); // Add your tools, prompts, and resources server.tool( { name: 'example_tool', description: 'An example tool', }, aSync () => { return { content: [{ type: 'text', text: 'Hello from the tool!' }], }; }, ); // Create and start the stdio transport const transport = new StdioTransport(server); transport.listen(); ``` -------------------------------- ### Install @tmcp/auth and Dependencies Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/auth/README.md Installs the necessary packages for using the @tmcp/auth library, including valibot for validation and pkce-challenge for PKCE flow support. ```bash pnpm install @tmcp/auth valibot pkce-challenge ``` -------------------------------- ### Install tmcp and Zod Adapter Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/tmcp/README.md Installs the tmcp package and the Zod adapter for schema validation, along with the Zod library itself. This is the initial setup for using tmcp with Zod. ```bash pnpm install tmcp # Choose your preferred schema library adapter pnpm install @tmcp/adapter-zod zod ``` -------------------------------- ### Install Dependencies with pnpm Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/playground/README.md Installs all project dependencies listed in the package.json file using the pnpm package manager. This is a prerequisite for building and running the project. ```bash pnpm install ``` -------------------------------- ### Example TMCP Project Structure Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/create-tmcp/README.md This illustrates the typical file and directory structure generated for a new TMCP project. It includes essential files like package.json and README.md, along with a src directory for server implementation and examples. ```bash my-project/ ├── package.json # Dependencies and scripts ├── README.md # Project documentation ├── src/ │ ├── index.js # Main server implementation │ └── example.js # Example server (optional) ``` -------------------------------- ### Install Dependencies for Development Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/transport-stdio/README.md Commands to install project dependencies, generate TypeScript declarations, and lint the code. These are standard development tasks for a Node.js project. ```bash # Install dependencies pnpm install # Generate TypeScript declarations pnpm generate:types # Lint the code pnpm lint ``` -------------------------------- ### Install @tmcp/session-manager-redis and redis Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/session-manager-redis/README.md Installs the necessary packages for using Redis-based session managers with TMCP. ```bash pnpm add @tmcp/session-manager-redis redis ``` -------------------------------- ### Install @tmcp/adapter-zod-v3 Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/adapter-zod-v3/README.md Installs the necessary packages for using the Zod v3 adapter with TMCP. This includes the adapter itself, Zod for schema definition, and the core TMCP library. ```bash pnpm add @tmcp/adapter-zod-v3 zod tmcp ``` -------------------------------- ### Start TMCP Playground Server Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/playground/README.md Starts the TMCP Playground MCP server. This command executes the compiled JavaScript code, making the server available for communication. ```bash node dist/index.js ``` -------------------------------- ### Install @tmcp/adapter-valibot Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/adapter-valibot/README.md Installs the Valibot adapter for TMCP along with its peer dependencies, valibot and tmcp. This command is typically run using a package manager like pnpm. ```bash pnpm add @tmcp/adapter-valibot valibot tmcp ``` -------------------------------- ### Install TMCP Session Manager Postgres Package Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/docs/src/content/000-getting-started.md Installs the @tmcp/session-manager-postgres package for managing sessions using PostgreSQL. This package is suitable for distributed MCP server setups requiring a robust database for session data. ```bash pnpm add @tmcp/session-manager-postgres ``` ```bash npm i @tmcp/session-manager-postgres ``` ```bash yarn add @tmcp/session-manager-postgres ``` ```bash bun add @tmcp/session-manager-postgres ``` -------------------------------- ### Initialize McpServer and Define Tool Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/docs/src/routes/(landing)/example-1.md This snippet shows how to create a new McpServer instance, configure it with a Valibot JSON schema adapter, and register a tool named 'add' that accepts two numbers and returns their sum. It also demonstrates setting up a StdioTransport to listen for incoming requests. ```typescript import { McpServer } from 'tmcp'; import { tool } from 'tmcp/utils'; import { ValibotJsonSchemaAdapter } from '@tmcp/adapter-valibot'; import { StdioTransport } from '@tmcp/transport-stdio'; import * as v from 'valibot'; export const server = new McpServer( { name: 'my-awesome-server', version: '1.0.0', }, { adapter: new ValibotJsonSchemaAdapter(), capabilities: { tools: {}, }, }, ); server.tool( { name: 'add', description: 'Adds two numbers', schema: v.object({ first: v.number(), second: v.number(), }), }, ({ first, second }) => { return tool.text(`${first}+${second} is ${first + second}`); }, ); const stdio = new StdioTransport(server); stdio.listen(); ``` -------------------------------- ### Install TMCP Session Manager Durable Objects Package Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/docs/src/content/000-getting-started.md Installs the @tmcp/session-manager-durable-objects package for managing sessions with Cloudflare Durable Objects. This is an option for serverless or distributed environments leveraging Cloudflare's infrastructure. ```bash pnpm add @tmcp/session-manager-durable-objects ``` ```bash npm i @tmcp/session-manager-durable-objects ``` ```bash yarn add @tmcp/session-manager-durable-objects ``` ```bash bun add @tmcp/session-manager-durable-objects ``` -------------------------------- ### Install TMCP Session Manager Redis Package Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/docs/src/content/000-getting-started.md Installs the @tmcp/session-manager-redis package for managing sessions using Redis. This is useful for distributed environments where session data needs to be shared across multiple servers. ```bash pnpm add @tmcp/session-manager-redis ``` ```bash npm i @tmcp/session-manager-redis ``` ```bash yarn add @tmcp/session-manager-redis ``` ```bash bun add @tmcp/session-manager-redis ``` -------------------------------- ### HTTP GET Request for Notification Stream Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/transport-http/README.md Shows an example of an HTTP GET request to establish a long-lived connection for receiving server notifications. It includes the `mcp-session-id` header, and the server responds with an event stream. ```http GET /mcp HTTP/1.1 mcp-session-id: optional-session-id ``` -------------------------------- ### Run Tests with Vitest Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/auth/README.md This command-line instruction shows how to run tests for the project using Vitest, a modern build tool and test runner. It assumes the project uses pnpm as its package manager. ```bash pnpm test ``` -------------------------------- ### Register a Basic Resource - TypeScript Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/docs/src/content/core/300-resource.md Demonstrates how to register a new resource using the `server.resource` method. It requires a configuration object with `uri`, `name`, and `description`, and a handler function that returns the resource content. The handler receives the resource `uri` as an argument. ```typescript server.resource( { uri: 'mymcp://name-of-the-resource.json', name: 'your-resource', description: 'A description for the LLM', title: 'Your Resource', }, (uri) => { return { contents: [ { uri, text: 'Content of the resource', mimeType: 'text/plain', // this is optional }, ], }; }, ); ``` -------------------------------- ### Complete TMCP Server Example with Stdio Transport and Zod Schema Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/transport-stdio/README.md A comprehensive example of a TMCP server using stdio transport, including schema validation with Zod. This script sets up a server, defines a tool with a schema, and starts the stdio listener. ```javascript #!/usr/bin/env node import { McpServer } from 'tmcp'; import { StdioTransport } from '@tmcp/transport-stdio'; import { ZodJsonSchemaAdapter } from '@tmcp/adapter-zod'; import { z } from 'zod'; const server = new McpServer( { name: 'example-server', version: '1.0.0', description: 'Example MCP server with stdio transport', }, { adapter: new ZodJsonSchemaAdapter(), capabilities: { tools: { listChanged: true }, }, }, ); // Add a tool with schema validation const GreetSchema = z.object({ name: z.string().describe('Name of the person to greet'), }); server.tool( { name: 'greet', description: 'Greet someone by name', schema: GreetSchema, }, aSync (input) => { return { content: [ { type: 'text', text: `Hello, ${input.name}!`, }, ], }; }, ); // Start the server const transport = new StdioTransport(server); transport.listen(); ``` -------------------------------- ### Multi-message Prompts Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/docs/src/content/core/500-prompt.md Illustrates how to create prompts that return multiple messages. This is useful for setting up conversational context, few-shot examples, or guiding the user through a series of interactions. ```APIDOC ## POST /api/prompts (multi-message) ### Description Registers a prompt that returns multiple messages, enabling multi-turn conversation templates. This is useful for providing context or examples within the prompt itself. ### Method POST ### Endpoint /api/prompts ### Parameters #### Request Body - **name** (string) - Required - A unique identifier for the prompt. - **description** (string) - Required - A brief description of the prompt for the user. - **title** (string) - Optional - A human-readable title for the prompt. ### Request Example ```json { "name": "api-design-review", "description": "Get help designing a REST API with examples", "title": "API Design Review" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example ```json { "status": "Prompt registered successfully" } ``` ``` -------------------------------- ### Initialize McpServer with Zod Adapter in JavaScript Source: https://context7.com/paoloricciuti/tmcp/llms.txt Demonstrates the initialization of the McpServer class with a Zod schema adapter. It configures server capabilities and shows how to access request context within tool handlers. ```javascript import { McpServer } from 'tmcp'; import { ZodJsonSchemaAdapter } from '@tmcp/adapter-zod'; import { z } from 'zod'; const adapter = new ZodJsonSchemaAdapter(); const server = new McpServer( { name: 'my-server', version: '1.0.0', description: 'My awesome MCP server', }, { adapter, capabilities: { tools: { listChanged: true }, prompts: { listChanged: true }, resources: { listChanged: true }, logging: {}, }, }, ); // Access request context within handlers server.tool( { name: 'context-aware', description: 'Uses request context' }, async () => { const { sessionId, auth, custom } = server.ctx; const { clientInfo, clientCapabilities } = server.ctx.sessionInfo || {}; return { content: [{ type: 'text', text: `Session: ${sessionId}` }] }; }, ); ``` -------------------------------- ### Quick Start: Configure OAuth with Fluent API Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/auth/README.md Demonstrates how to set up a custom OAuth 2.1 server using the fluent API provided by @tmcp/auth. This includes defining the issuer, scopes, client memory, and custom handlers for authorization, token exchange, token verification, and revocation. It also shows how to configure CORS and Bearer token validation. ```javascript import { OAuth, SimpleProvider } from '@tmcp/auth'; // Custom OAuth server with handlers const auth = OAuth.issuer('https://auth.example.com') .scopes('read', 'write') .memory([ { client_id: 'test-client', client_secret: 'test-secret', redirect_uris: ['https://app.example.com/callback'], client_id_issued_at: Math.floor(Date.now() / 1000), }, ]) .handlers({ async authorize(request) { // Generate authorization code and redirect const redirectUrl = new URL(request.redirectUri); redirectUrl.searchParams.set('code', 'auth_code_' + Date.now()); if (request.state) { redirectUrl.searchParams.set('state', request.state); } return new Response(null, { status: 302, headers: { Location: redirectUrl.toString() }, }); }, async exchange(request) { if (request.type === 'authorization_code') { return { access_token: 'access_token_' + Date.now(), token_type: 'bearer', expires_in: 3600, refresh_token: 'refresh_token_' + Date.now(), }; } else if (request.type === 'refresh_token') { return { access_token: 'new_access_token_' + Date.now(), token_type: 'bearer', expires_in: 3600, refresh_token: request.refreshToken, }; } throw new Error('Unsupported grant type'); }, async verify(token) { // Verify token and return auth info if (token.startsWith('access_token_')) { return { token, clientId: 'test-client', scopes: ['read', 'write'], expiresAt: Math.floor(Date.now() / 1000) + 3600, }; } throw new Error('Invalid token'); }, async revoke(client, request) { // Revoke the token console.log( `Revoking token ${request.token} for client ${client.client_id}`, ); }, }) .cors({ origin: 'https://app.example.com', credentials: true }) .bearer(['read']) .build(); // Handle requests async function handleRequest(request) { return ( (await auth.respond(request)) || new Response('Not Found', { status: 404 }) ); } ``` -------------------------------- ### Initialize McpServer with Capabilities - TypeScript Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/docs/src/content/core/100-mcp-server.md Shows how to initialize the McpServer with specific capabilities like tools, resources, prompts, logging, and completions. Defining capabilities is essential for the server to respond to corresponding method invocations. An adapter is still set to undefined for this example. ```typescript const server = new McpServer( { name: 'my-awesome-server', version: '1.0.0', }, { adapter: undefined, capabilities: { tools: { listChanged: true, }, resources: { subscribe: true, listChanged: true, }, prompts: { listChanged: true, }, logging: {}, completions: {}, }, }, ); ``` -------------------------------- ### Install @tmcp/transport-in-memory Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/transport-in-memory/README.md Installs the @tmcp/transport-in-memory package as a development dependency using pnpm. ```bash pnpm add -D @tmcp/transport-in-memory ``` -------------------------------- ### Install @tmcp/adapter-effect Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/adapter-effect/README.md Installs the @tmcp/adapter-effect package along with its peer dependencies, effect and tmcp, using pnpm. ```bash pnpm add @tmcp/adapter-effect effect tmcp ``` -------------------------------- ### Implement Dynamic Tool Description using Getters Source: https://github.com/paoloricciuti/tmcp/blob/main/README.md Illustrates using JavaScript getters to define dynamic properties, such as the tool description, which can change based on runtime context like the connected client. This allows for context-aware tool descriptions. ```javascript server.tool( { name: 'search', get description() { const client = server.ctx.sessionInfo?.clientInfo?.name; if (client === 'claude-code') { return 'Search the codebase for files, symbols, or text patterns'; } return 'Search for information'; }, }, () => { return { content: [{ type: 'text', text: 'Search results...' }] }; }, ); ``` -------------------------------- ### Install @tmcp/transport-http and tmcp Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/transport-http/README.md Installs the necessary packages for the HTTP transport and the core TMCP library using pnpm. ```bash pnpm add @tmcp/transport-http tmcp ``` -------------------------------- ### Install @tmcp/adapter-arktype Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/adapter-arktype/README.md Installs the ArkType adapter for TMCP along with its peer dependencies, arktype and tmcp. ```bash pnpm add @tmcp/adapter-arktype arktype tmcp ``` -------------------------------- ### Initialize Basic McpServer - TypeScript Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/docs/src/content/core/100-mcp-server.md Demonstrates the basic initialization of the McpServer class with server name and version. This minimal setup allows responses to 'ping' and 'initialize' requests. No specific capabilities are defined, relying on default behavior. ```typescript const server = new McpServer( { name: 'a-super-basic-server', version: '1.0.0', }, { adapter: undefined, capabilities: {}, }, ); ``` -------------------------------- ### Install @tmcp/session-manager Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/session-manager/README.md Installs the @tmcp/session-manager package using pnpm. This is the first step to integrate session management into your TMCP transport. ```bash pnpm add @tmcp/session-manager ``` -------------------------------- ### Define MCP Handlers with tmcp/utils Helpers (TypeScript) Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/tmcp/README.md Demonstrates how to use the `tmcp/utils` helpers (`tool`, `resource`, `prompt`, `complete`) to define MCP handlers, reducing boilerplate compared to manual response construction. It shows examples for creating text, media, and mixed tool responses, as well as resource and prompt responses. ```typescript import { tool, resource, prompt, complete } from 'tmcp/utils'; // Without helpers – lots of envelope noise server.tool( { name: 'health-check', description: 'A health check tool' }, async () => ({ content: [{ type: 'text', text: 'ok' }], }), ); // With helpers – just describe the payload once server.tool( { name: 'health-check', description: 'A health check tool' }, async () => tool.text('ok'), ); server.tool( { name: 'profile-picture', description: 'Your profile picture' }, async () => tool.media('image', await loadPng(), 'image/png'), ); server.tool( { name: 'get-images', description: 'Get the orders details and the images of all the products', schema: v.object({ items: v.array(ItemsSchema), }), }, async () => { const orders = await loadOrders(); const images = await loadImages(orders); return tool.mix( [ tool.text("Here's your images"), ...images.map((img) => tool.media('image', img)), ], orders, ); }, ); server.resource( { name: 'readme', description: 'Top-level README', uri: 'file://README.md', }, async (uri) => resource.text(uri, await readFile(uri, 'utf8'), 'text/markdown'), ); server.prompt( { name: 'explain', description: '', schema: v.object({ topic: v.string() }), }, async ({ topic }) => prompt.message(`Explain ${topic} like I am five.`), ); server.template( { name: 'users', description: 'Supports completion', uri: 'users/{id}', complete: { id: async (arg) => complete.values(await findMatchingIds(arg), false), }, }, async (uri) => resource.blob(uri, await fetchUserBlob(uri)), ); ``` -------------------------------- ### Configure Resource Icons in TypeScript Source: https://github.com/paoloricciuti/tmcp/blob/main/apps/docs/src/content/core/300-resource.md Demonstrates how to specify icons for an MCP resource using the 'icons' property in a TypeScript configuration object. It shows examples of remote URLs and data URIs for icons, and notes that clients have restrictions on displaying icons based on server locality. ```typescript server.resource( { uri: 'mymcp://name-of-the-resource.json', name: 'your-resource', description: 'A description for the LLM', title: 'Your Resource', icons: [ { src: 'https://dantemcp.com/date.png', }, { src: 'data:image/png;base64,...', }, ], }, (uri) => { return { contents: [ { uri, text: 'Content of the resource', mimeType: 'text/plain', // this is optional }, ], }; }, ); ``` -------------------------------- ### Install @tmcp/transport-sse and tmcp Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/transport-sse/README.md Installs the necessary packages for using the SSE transport with TMCP. This includes the transport package itself and the core TMCP library. ```bash pnpm add @tmcp/transport-sse tmcp ``` -------------------------------- ### Install @tmcp/session-manager-postgres Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/session-manager-postgres/README.md Installs the @tmcp/session-manager-postgres package using pnpm. This is the initial step to integrate PostgreSQL-based session management into your TMCP transport implementations. ```bash pnpm add @tmcp/session-manager-postgres ``` -------------------------------- ### Initialize and Configure McpServer (JavaScript) Source: https://github.com/paoloricciuti/tmcp/blob/main/packages/tmcp/README.md Sets up an McpServer instance with a ZodJsonSchemaAdapter and registers various tools, prompts, resources, and templates. It demonstrates both individual and batch registration methods for these components. ```javascript // server.js import { McpServer } from 'tmcp'; import { ZodJsonSchemaAdapter } from '@tmcp/adapter-zod'; import { addTool, multiplyTool } from './tools/calculator.js'; import { codeReviewPrompt } from './prompts/code-review.js'; import { readmeResource } from './resources/files.js'; import { userFileTemplate } from './templates/user-files.js'; const server = new McpServer( { name: 'my-server', version: '1.0.0', }, { adapter: new ZodJsonSchemaAdapter(), } ); // Register multiple tools at once server.tools([addTool, multiplyTool]); // Or register individually server.tool(addTool); // Same for prompts, resources, and templates server.prompts([codeReviewPrompt]); server.resources([readmeResource]); server.templates([userFileTemplate]); ``` -------------------------------- ### Register Static and Dynamic Resources - JavaScript Source: https://context7.com/paoloricciuti/tmcp/llms.txt Shows how to register static resources and dynamic template resources with McpServer. Static resources provide fixed content, while templates are URI-based and support parameter extraction and autocomplete. This example includes text, JSON, and binary resources. ```javascript import { McpServer } from 'tmcp'; import { ZodJsonSchemaAdapter } from '@tmcp/adapter-zod'; import * as fs from 'fs/promises'; const server = new McpServer( { name: 'resource-server', version: '1.0.0' }, { adapter: new ZodJsonSchemaAdapter(), capabilities: { resources: { listChanged: true, subscribe: true } } }, ); // Static resource server.resource( { name: 'readme', description: 'Project README file', uri: 'file://README.md', mimeType: 'text/markdown', }, async (uri) => { const content = await fs.readFile('./README.md', 'utf8'); return { contents: [{ uri, text: content, mimeType: 'text/markdown' }], }; }, ); // Dynamic template resource with URI parameters server.template( { name: 'user-profile', description: 'Get user profile by ID', uri: 'users/{userId}/profile', complete: { userId: async (arg) => ({ completion: { values: ['user-123', 'user-456', 'user-789'], total: 3, hasMore: false, }, }), }, // Optional: list available resources for this template list: async () => [ { uri: 'users/user-123/profile', name: 'Alice Profile' }, { uri: 'users/user-456/profile', name: 'Bob Profile' }, ], }, async (uri, params) => { const user = await getUserById(params.userId); return { contents: [ { uri, mimeType: 'application/json', text: JSON.stringify(user), }, ], }; }, ); // Binary resource (blob) server.resource( { name: 'logo', description: 'Company logo image', uri: 'assets://logo.png', mimeType: 'image/png', }, async (uri) => { const imageBuffer = await fs.readFile('./logo.png'); return { contents: [{ uri, blob: imageBuffer.toString('base64'), mimeType: 'image/png' }], }; }, ); ```