A sample implementation of a Machine Conversation Protocol (MCP) server with HTTP support. This server provides a simple phonebook API that can be accessed via HTTP.
- MCP server implementation following the JSON-RPC 2.0 protocol
- HTTP interface for API access
- Simple phonebook API with CRUD operations
- Tool-based architecture for extensibility
- Make sure you have Deno installed
- Clone this repository
- Run the server using one of the provided tasks
# Install Deno (if not already installed)
curl -fsSL https://deno.land/x/install/install.sh | sh
# Clone the repository (example)
git clone https://github.com/yourusername/sample-mcp-server.git
cd sample-mcp-server
# Run the server
deno task startThe server runs in HTTP mode, listening for HTTP requests on a specified port.
You can start the server using the provided task in deno.json:
# Start the server
deno task startOr you can run the main.ts file directly with command-line arguments:
# Start the server
deno run --allow-read --allow-write --allow-net main.ts
# Specify a custom port (default is 8000)
deno run --allow-read --allow-write --allow-net main.ts --port=3000For development with file watching:
deno task devRun the tests:
deno task testTest the HTTP server specifically:
# Start the server in HTTP mode
deno task start:http
# In another terminal, run the HTTP test script
deno run --allow-net test-http-server.tsThe server implements the Machine Conversation Protocol (MCP) using JSON-RPC 2.0. It supports the following methods:
initialize: Initialize the MCP sessiontools/list: List available toolstools/call: Call a specific tool
list_persons: List all persons in the phone bookget_person: Get a specific person by IDadd_person: Add a new person to the phone bookupdate_person: Update an existing persondelete_person: Delete a person from the phone booksearch_persons: Search persons by name, email, or phone
curl -X POST http://localhost:8000 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize"
}'curl -X POST http://localhost:8000 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list"
}'curl -X POST http://localhost:8000 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "add_person",
"arguments": {
"name": "John Doe",
"email": "[email protected]",
"phone": "123-456-7890"
}
}
}'main.ts: Main entry pointdeno.json: Project configurationdatabase.json: A sample database file implemented as JSONsrc/models/types.ts: Type definitions for the domain modelsrc/services/database.service.ts: Database servicesrc/services/tools.service.ts: Tools servicesrc/tools/: Tool implementations