This guide is designed to help you transition from using FastMCP to the standard Model Context Protocol TypeScript SDK. It provides a step-by-step plan, with detailed instructions that even a junior developer can follow.
- Review your existing FastMCP server code.
- Identify which parts of your code rely on FastMCP's abstractions (e.g., tool registration, transport initialization).
- Take note of any configuration or dependencies that may need to be updated.
- Remove or comment out FastMCP specific dependencies if they are no longer needed.
- Install the standard SDK and its dependencies by running:
npm install @modelcontextprotocol/sdk
npm install zod
- Create a new file (for example,
server.ts
ormcp-server.ts
). - Use the sample code below as a starting point:
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { z } from 'zod';
const server = new McpServer({
name: 'MyMCPServer',
version: '1.0.0'
});
// Define a sample tool
const echoTool = {
name: 'echo',
description: 'Echoes the provided message',
parameters: z.object({ message: z.string() }),
execute: async (args) => ({
content: [{ type: 'text', text: `You said: ${args.message}` }]
})
};
server.addTool(echoTool);
// Setup the transport (using stdio for this example)
const transport = new StdioServerTransport();
await server.connect(transport);
console.log('MCP Server started!');
- Convert your FastMCP tool registrations to the standard method provided by the SDK.
- For example, if you have tools like
generateVideo
orretrieveVoiceIds
, register them using:
server.addTool(yourToolObject);
- Refer to the official SDK documentation for more examples and best practices: Model Context Protocol TypeScript SDK.
- Decide which transport suits your use case (e.g.,
StdioServerTransport
for local debugging orSSEServerTransport
for a web server). - Adjust your server startup code to initialize the chosen transport.
- Run your new server file with Node.js:
node server.ts
- Use tools like curl, Postman, or simply check the logs in your terminal to ensure the server starts correctly and the tools are registered.
- If errors occur, use console logging to debug.
- Compare your implementation with examples from the official SDK repository.
- Verify that all tool endpoints are reachable and behaving as expected.
By following these steps, you will migrate from FastMCP to the full SDK, giving you more control and flexibility in your MCP server implementation. For further reading and detailed examples, consult the official Model Context Protocol TypeScript SDK Documentation.
Happy coding!