This is a simple MCP server built with the @modelcontextprotocol/sdk
, express
, and zod
.
- Tools:
get-time
- returns the current time. - Resources:
sample-resource
- returns a sample resource.
-
Clone the repository:
git clone https://github.com/your-username/simple-mcp-server.git cd simple-mcp-server
-
Install dependencies:
npm install
To run the server, use the following command:
npm start
The server will start on http://localhost:3000/mcp
. You can send POST requests to this endpoint to interact with the server.
Request:
curl -X POST -H "Content-Type: application/json" -d '{
"id": "1",
"type": "tool",
"name": "get-time",
"arguments": {}
}' http://localhost:3000/mcp
Response:
{
"id": "1",
"result": {
"content": [
{
"type": "text",
"text": "{\"time\":\"2023-10-27T12:34:56.789Z\"}"
}
],
"structuredContent": {
"time": "2023-10-27T12:34:56.789Z"
}
}
}
Request:
curl -X POST -H "Content-Type: application/json" -d '{
"id": "2",
"type": "resource",
"uri": "sample-resource"
}' http://localhost:3000/mcp
Response:
{
"id": "2",
"result": {
"contents": [
{
"uri": "sample-resource:",
"text": "This is a sample resource"
}
]
}
}