MCP Server Starter
About
A TypeScript starter template for building Model Context Protocol (MCP) servers.
Details
- Author
- thesethrose
- Categories
- Developer Tools
Jump to
Setup
Install MCP Server Starter in your MCP client (Claude Desktop, Cursor, Windsurf, and others).
Repository: https://github.com/thesethrose/MCP-Server-Starter
Follow the installation instructions in the repository README, then restart your MCP client.
The Model Context Protocol (MCP) is a specialized framework designed to streamline the process of enabling AI agents to interact with a wide array of tools. This starter template helps you quickly build a Model Context Protocol (MCP) server using TypeScript. It provides a robust foundation that you can easily extend to create advanced MCP tools and seamlessly integrate them with various AI platforms.
- MCP Servers: These servers act as bridges, exposing APIs, databases, and code libraries to external AI hosts. By implementing an MCP server in TypeScript, developers can share data sources or computational logic in a standardized way using JSON-RPC 2.0.
- MCP Clients: These are the consumer-facing side of MCP, communicating with servers to query data or perform actions. MCP clients use TypeScript SDKs, ensuring type-safe interactions and uniform approach to tool usage.
- MCP Hosts: Systems such as Claude, Cursor, Windsurf, Cline, and other TypeScript-based platforms coordinate requests between servers and clients, ensuring seamless data flow. A single MCP server can thus be accessed by multiple AI hosts without custom integrations.
The MCP TypeScript SDK provides core classes for building servers:
import { Server } from "@modelcontextprotocol/sdk/server/index.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; const server = new Server({ name: "mcp-server-starter", version: "1.0.0", capabilities: { tools: {}, // Enable tools capability resources: {}, // Enable resource access prompts: {}, // Enable prompt handling streaming: true // Enable streaming responses } }); // Connect transport const transport = new StdioServerTransport(); await server.connect(transport);
By using MCP, developers no longer need complex custom code to integrate new tools or services. Instead, they build an MCP server and make it available to supported hosts.
- Node.js (v18 or later): A modern version of Node.js that takes advantage of the latest JavaScript features and performance improvements.
- npm (v7 or later): Ensures compatibility for installing and managing packages.
- VS Code with Dev Containers extension: Allows you to quickly spin up a reproducible development environment, making collaboration easier and more efficient.
A typical file layout for the MCP server template may look like this:
mcp-server/ ├── .devcontainer/ # Dev container configuration │ └── devcontainer.json ├── src/ │ ├── index.ts # MCP Server main entry point │ └── examples/ # Example tool implementations │ ├── calculator.ts # Calculator tool example │ └── rest-api.ts # REST API tool example ├── package.json # Project configuration └── tsconfig.json # TypeScript configuration
The.devcontainerdirectory streamlines container-based development, while thesrc/folder houses the main server logic and examples of custom tools. This structure keeps your project organized and easy to navigate.
To install MCP Server Starter for any supported client:
# For Claude npx -y @smithery/cli install @TheSethRose/mcp-server-starter --client claude # For Cursor npx -y @smithery/cli install @TheSethRose/mcp-server-starter --client cursor # For Windsurf npx -y @smithery/cli install @TheSethRose/mcp-server-starter --client windsurf # For Cline npx -y @smithery/cli install @TheSethRose/mcp-server-starter --client cline # For TypeScript npx -y @smithery/cli install @TheSethRose/mcp-server-starter --client typescript
- Clone this template: Retrieve the repository files from your preferred source.
- Open in VS Code with Dev Containers: If you have the Dev Containers extension installed, you will be prompted to open this project inside a container.
- Install dependencies:
npm install
MCP tools must return responses in a specific format to ensure proper communication with AI hosts. Here's the structure:
interface ToolResponse { content: ContentItem[]; isError?: boolean; metadata?: Record<string, unknown>; } interface ContentItem { type: string; text?: string; mimeType?: string; data?: unknown; }
- text: Plain text content
- code: Code snippets with optional language specification
- image: Base64-encoded images with MIME type
- file: File content with MIME type
- error: Error messages (whenisErroris true)
return { content: [ { type: "text", text: "Operation completed successfully" }, { type: "code", text: "console.log('Hello, World!')", mimeType: "application/javascript" } ] };
When developing MCP tools, follow these security guidelines:
- Input Validation:
- Always validate input parameters using Zod schemas
- Implement strict type checking
- Sanitize user inputs before processing
- Use thestrict()option in schemas to prevent extra properties
- Never expose internal error details to clients
- Implement proper error boundaries
- Log errors securely
- Return user-friendly error messages
- Implement proper cleanup procedures
- Handle process termination signals
- Close connections and free resources
- Implement timeouts for long-running operations
- Use secure transport protocols
- Implement rate limiting
- Store sensitive data securely
- Use environment variables for configuration
const SecureSchema = z.object({ input: z.string() .min(1) .max(1000) .transform(str => str.trim()) .pipe(z.string().regex(/^[a-zA-Z0-9\s]+$/)) }); server.tool( "secure_tool", SecureSchema.shape, async (params) => { try { // Implement rate limiting await rateLimiter.checkLimit(); // Process validated input const result = await processSecurely(params.input); return { content: [{ type: "text", text: result }] }; } catch (error) { // Log error internally logger.error(error); // Return safe error message return { content: [{ type: "text", text: "An error occurred processing your request" }], isError: true }; } } );
MCP supports streaming responses for long-running operations:
server.tool( "stream_data", StreamSchema.shape, async function* (params) { for (const chunk of dataStream) { yield { content: [{ type: "text", text: chunk }] }; } } );
You can define custom content types for specialized data:
interface CustomContent extends ContentItem { type: "custom"; data: { format: string; value: unknown; }; }
server.tool( "async_operation", AsyncSchema.shape, async (params) => { const operation = await startAsyncOperation(); while (!operation.isComplete()) { await operation.wait(); } return { content: [{ type: "text", text: await operation.getResult() }] }; } );
describe('Calculator Tool', () => { let server: McpServer; beforeEach(() => { server = new McpServer({ name: "test-server", version: "1.0.0" }); registerCalculatorTool(server); }); test('adds numbers correctly', async () => { const result = await server.executeTool('calculate', { a: 5, b: 3, operation: 'add' }); expect(result.content[0].text).toBe('8'); }); });
- Tool registration
- Request/response flow
- Error handling
- Performance metrics
function logMessage(level: 'info' | 'warn' | 'error', message: string) { console.error(\[${level.toUpperCase()}] ${message}\); }
process.on('uncaughtException', (error: Error) => { logMessage('error', \Uncaught error: ${error.message}\); // Implement error reporting });
MCP supports multiple transport protocols:
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; const transport = new StdioServerTransport(); await server.connect(transport);
import { WebSocketServerTransport } from "@modelcontextprotocol/sdk/server/websocket.js"; const transport = new WebSocketServerTransport({ port: 3000 }); await server.connect(transport);
import { Transport } from "@modelcontextprotocol/sdk/server/transport.js"; class CustomTransport implements Transport { // Implement transport methods }
const server = new McpServer({ name: "mcp-server", version: "1.0.0", capabilities: { tools: {}, // Enable tools capability streaming: true, // Enable streaming support customContent: ["myFormat"], // Define custom content types metadata: true // Enable metadata support } });
This MCP server template supports multiple AI platforms out of the box:
- Claude Desktop:
- Provides a chat-based environment
- Supports all MCP capabilities
- Ideal for conversational AI interactions
- AI-powered development environment
- Full tool integration support
- Perfect for coding assistance
- Modern AI development platform
- Complete MCP protocol support
- Streamlined workflow integration
- Command-line AI interface
- Tool-focused interactions
- Efficient terminal-based usage
- Native TypeScript support
- Type-safe tool development
- Seamless SDK integration
Each client can be configured using the appropriate Smithery CLI command:
npx -y @smithery/cli run @TheSethRose/mcp-server-starter --client [client-name]
Replace[client-name]with one of:claude,cursor,windsurf,cline, ortypescript.
A convenient way to run this MCP server is through Smithery, a centralized platform for discovering and publishing MCP servers. Smithery simplifies deployment and ensures your server can be integrated into various AI workflows.
You can immediately execute this server via the Smithery CLI:
npx -y @smithery/cli@latest run mcp-server-template --config "{}"
Smithery automatically fetches, installs, and runs the server from its latest release, requiring minimal setup from you.
If you have developed new tools or made local modifications and wish to share them, consider publishing your customized server:
- Create an account onSmithery.
- Follow their deployment instructions to bundle and publish your MCP server.
- Other users can then run your server through Smithery by referencing your unique package name.
- A centralized registry to discover and share MCP servers.
- Simplified deployment, removing repetitive setup.
- A community-driven approach where developers contribute diverse tools.
- Easy integration with popular AI hosts.
Cursor is another AI development environment that supports MCP. To incorporate your server into Cursor:
- Selectstdioas the transport type.
- Provide a descriptiveName.
- Set the command, for example:node /path/to/your/mcp-server/build/index.js.
Cursor then detects and lists your tools. During AI-assisted coding sessions or prompt-based interactions, it will call your MCP tools whenever relevant. You can also instruct the AI to use a specific tool by name.
Claude Desktop provides a chat-based environment where you can leverage MCP tools. To include your server:
{ "mcpServers": { "mcp-server": { "command": "node", "args": [ "/path/to/your/mcp-server/build/index.js" ] } } }
When you interact with Claude Desktop, it can now invoke the MCP tools you have registered. If a user's request aligns with any of your tool's functionality, Claude will prompt to use that tool.
- Use TypeScriptfor better type checking, clearer code organization, and easier maintenance over time.
- Adopt consistent patternsfor implementing tools:
- Keep each tool in its own file
- Use descriptive schemas with proper documentation
- Implement comprehensive error handling
- Return properly formatted content
- Add JSDoc comments to explain functionality
- Document parameters and return types
- Include examples where helpful
- Test tool functionality
- Debug request/response flow
- Verify schema validation
- Check error handling
- Verify input validation
- Test error scenarios
- Check response formatting
- Ensure proper integration with hosts
- Use proper content types
- Implement proper error handling
- Validate all inputs and outputs
- Handle network requests safely
- Format responses consistently
For further information on the MCP ecosystem, refer to:
- Model Context Protocol Documentation: Detailed coverage of MCP architecture, design principles, and more advanced usage examples.
- Smithery - MCP Server Registry: Guidelines for publishing your tools to Smithery and best practices for their registry.
- MCP TypeScript SDK Documentation: Comprehensive documentation of the TypeScript SDK.
- MCP Security Guidelines: Detailed security best practices and recommendations.
By following this template and best practices, you can quickly build a robust MCP server that opens your tools to a broad range of AI hosts. This expanded approach ensures easier maintenance, better type safety, and a smooth user experience when harnessing the capabilities of modern AI systems.
- Website:https://www.sethrose.dev
- 𝕏 (Twitter):https://x.com/TheSethRose
- 🦋 (Bluesky):https://bsky.app/profile/sethrose.dev
- Type Safety:
- Leverage TypeScript's type system for robust tool definitions
- Use Zod schemas for runtime validation
- Define clear interfaces for tool parameters and responses
- UseStdioServerTransportfor local process communication
- ImplementWebSocketServerTransportfor network-based tools
- Consider custom transports for specific use cases
- Clearly define server capabilities during initialization
- Implement proper capability negotiation
- Handle capability-specific errors gracefully
- Implement user consent flows for sensitive operations
- Validate all inputs using TypeScript types and Zod schemas
- Handle errors securely without exposing internal details
This is a web browser that enables your coding agent, such as Claude Code, to visit websites on your behalf and assist you in identifying bugs or creating UI test cases.
An MCP server to help AI assistants to answer questions and generate AccelByte Extend SDK code more effectively .
Local stdio MCP server that lets AI coding agents read and maintain structured architecture, rules, and decisions directly from your repository.
Official Context7 MCP server that brings up-to-date, version-specific library documentation and code examples into AI coding prompts.
Remote, no-auth MCP server providing AI-powered codebase context and answers
Instead of direct calling MCP tools, mcpcode server transforms MCP tool calls into TypeScript programs, enabling smarter, lower-latency orchestration by LLMs.
Help agents automatically write and test stories for your UI components
Official Svelte MCP server, provides docs and suggestions on the generated code.
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.





