xyz-abc-30/MCP-Server-setup
If you are the rightful owner of MCP-Server-setup and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This document provides a comprehensive overview of a Model Context Protocol (MCP) server implementation using TypeScript, designed for user and project management.
Example MCP Server
A complete Model Context Protocol (MCP) server implementation with TypeScript boilerplate code. This server provides example tools and resources for user and project management.
Features
Tools
get_user
: Retrieve user information by IDlist_users
: List all users in the systemcreate_user
: Create a new user with validationget_projects
: Get projects with optional status filtering
Resources
users://all
: Complete JSON list of all usersprojects://all
: Complete JSON list of all projectssystem://status
: Current system status and statistics
Prerequisites
- Node.js 18.0.0 or higher
- npm or yarn package manager
Installation & Setup
1. Clone or Create Project Directory
mkdir my-mcp-server
cd my-mcp-server
2. Initialize the Project
Create the following file structure:
my-mcp-server/
āāā src/
ā āāā index.ts
āāā package.json
āāā tsconfig.json
āāā README.md
3. Install Dependencies
npm install
This will install:
@modelcontextprotocol/sdk
: Core MCP SDKtypescript
: TypeScript compiler@types/node
: Node.js type definitions
4. Set Up Source Files
-
Create a
src
directory:mkdir src
-
Copy the main server code into
src/index.ts
(provided in the artifact above)
5. Build the Project
npm run build
This compiles the TypeScript code to JavaScript in the build/
directory.
Running the Server
Development Mode
npm run dev
This builds and runs the server, outputting status to stderr.
Production Mode
npm start
Runs the compiled server from the build directory.
Watch Mode (Development)
npm run watch
Automatically rebuilds when source files change.
Testing the Server
The MCP server communicates via stdio (standard input/output). You can test it using:
1. Direct JSON-RPC Communication
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | npm start
2. Using Claude Desktop or Compatible MCP Client
Add to your Claude Desktop configuration:
{
"mcpServers": {
"example-server": {
"command": "node",
"args": ["/path/to/your/my-mcp-server/build/index.js"]
}
}
}
Configuration
Environment Variables
You can extend the server to use environment variables:
export MCP_SERVER_PORT=3000
export MCP_SERVER_LOG_LEVEL=debug
Custom Configuration
Create a config.json
file:
{
"server": {
"name": "my-custom-mcp-server",
"version": "1.0.0"
},
"features": {
"enableUserCreation": true,
"maxUsers": 1000
}
}
Development
Project Structure
my-mcp-server/
āāā src/
ā āāā index.ts # Main server implementation
ā āāā handlers/ # Tool and resource handlers
ā āāā types/ # TypeScript type definitions
ā āāā utils/ # Utility functions
āāā build/ # Compiled JavaScript (generated)
āāā package.json # Dependencies and scripts
āāā tsconfig.json # TypeScript configuration
āāā README.md # This file
Adding New Tools
- Add tool definition to the
ListToolsRequestSchema
handler:
{
name: "my_new_tool",
description: "Description of what the tool does",
inputSchema: {
type: "object",
properties: {
param1: { type: "string", description: "Parameter description" }
},
required: ["param1"]
}
}
- Add handler in the
CallToolRequestSchema
handler:
case "my_new_tool":
return this.handleMyNewTool(args as { param1: string });
- Implement the handler method:
private async handleMyNewTool(args: { param1: string }) {
// Your tool logic here
return {
content: [{
type: "text" as const,
text: `Result: ${args.param1}`
}]
};
}
Adding New Resources
- Add resource definition to
ListResourcesRequestSchema
handler - Add handler case in
ReadResourceRequestSchema
handler - Return appropriate content with correct MIME type
Debugging
Enable Debug Logging
DEBUG=mcp:* npm run dev
Common Issues
- Port already in use: The server uses stdio by default, no ports
- Permission denied: Ensure the built file is executable
- Module not found: Run
npm install
andnpm run build
Logs
Server logs are output to stderr to avoid interfering with stdio communication:
npm start 2>server.log
Deployment
Local Installation
npm run build
npm link
Then use example-mcp-server
globally.
Docker (Optional)
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY build/ ./build/
CMD ["node", "build/index.js"]
API Reference
Tools
get_user
- Parameters:
{ userId: number }
- Returns: User object with id, name, email, role
- Errors: User not found
list_users
- Parameters: None
- Returns: Array of all user objects
create_user
- Parameters:
{ name: string, email: string, role: "admin"|"user" }
- Returns: Created user object
- Errors: Invalid email, duplicate email
get_projects
- Parameters:
{ status?: "active"|"planning"|"completed" }
- Returns: Array of project objects (filtered if status provided)
Resources
users://all
- Type: application/json
- Content: Complete user list
projects://all
- Type: application/json
- Content: Complete project list
system://status
- Type: text/plain
- Content: System status report
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
MIT License - see LICENSE file for details
Support
For issues and questions:
- Check the MCP documentation
- Open an issue on GitHub
- Review the server logs for debugging information