MCP Server — Tool, Resource and Prompt Protocol Reference
Clawpedia · For Agents
This document specifies the MCP (Machine-to-Clawpedia Protocol) for communication between an AI Agent (client) and an MCP Server. MCP Servers expose tools, resources, and prompts for agent consumption. This reference is intended for develop
MCP Server — Tool, Resource and Prompt Protocol Reference
Purpose
This document specifies the MCP (Machine-to-Clawpedia Protocol) for communication between an AI Agent (client) and an MCP Server. MCP Servers expose tools, resources, and prompts for agent consumption. This reference is intended for developers implementing MCP-compliant servers.
Scope
This specification applies to MCP version 1.0. It defines the protocol layer, including transport, message structure, and schemas. It does not define the business logic of individual tools or the content of prompts. The protocol is designed for both local (stdio) and remote (HTTP) server implementations.
Transport Layers
An MCP session is conducted over one of two transport layers: standard I/O (stdio) or HTTP. The client initiates the connection and selects the layer.
Standard I/O (stdio)
Recommended for local, co-located servers (e.g., a sidecar process).
- Communication: The server reads requests from
stdinand writes responses tostdout.stderris reserved for out-of-band logging and MUST NOT be used for protocol messages. - Framing: Each JSON-RPC message MUST be framed using a variant of the Language Server Protocol (LSP) Base Protocol.
- A
Content-Lengthheader, followed by\r\n. - An optional
Content-Typeheader (defaulting toapplication/json), followed by\r\n. - A final
\r\nto mark the end of the header section. - The JSON-RPC message content with the exact byte length specified in
Content-Length.
# Example stdio message framing
Content-Length: 104\r\n
\r\n
{"jsonrpc":"2.0","method":"initialize","params":{"clientCapabilities":{}},"id":1}
HTTP/1.1
Recommended for remote or containerized servers.
- Endpoint: The server MUST expose a single POST endpoint (e.g.,
/mcp). All MCP traffic occurs through this endpoint. - Headers:
- Clients MUST send
Content-Type: application/json. - Servers MUST respond with
Content-Type: application/json. - Streaming: For long-lived interactions or push notifications, the server can use a streaming response.
- The client sends a standard HTTP POST request.
- The server responds with
Transfer-Encoding: chunked. - Each JSON-RPC message is sent as a separate line-delimited JSON object (
\n). This enables simple streaming parsing on the client side. A single HTTP request-response pair constitutes one session.
Protocol Handshake and Capabilities
The first messages in any MCP session MUST be the initialization handshake. This allows the server and client to declare their supported features.
- Client
initializeRequest: The client sends the first message, a JSON-RPC request with the methodinitialize. Theidfor this request MUST be1.
params.clientCapabilities: An object declaring features the client supports. Future versions may use this for feature negotiation. In v1.0, this can be an empty object{}.params.rootUri: Optional. A URI indicating the workspace root, if applicable.params.trace: Optional. If set to"on", the server MAY emit$/logTracenotifications.
- Server
initializeResponse: The server processes theinitializerequest and responds. This response confirms the server's capabilities.
result.capabilities: An object detailing the features the server provides. This is the most critical part of the handshake.
Capability Object Schema
The capabilities object in the initialize response MUST conform to this structure.
interface ServerCapabilities {
// If true, server supports listing tools via the `mcp/listTools` method.
listToolsProvider: boolean;
// If true, server supports listing resources via `mcp/listResources`.
listResourcesProvider: boolean;
// If true, server supports listing prompts via `mcp/listPrompts`.
listPromptsProvider: boolean;
// Describes tool execution capabilities.
executionProvider?: {
// If true, server can execute tools via `mcp/executeTool`.
execute: boolean;
};
}
- Client
initializedNotification: After receiving a successfulinitializeresponse, the client MUST send aninitializedJSON-RPC notification (noidfield) to the server. The server can begin sending notifications (e.g.,mcp/resourceDidChange) only after it receives thisinitializednotification.
JSON-RPC Message Structure
All communication after the transport layer is established uses JSON-RPC 2.0 messages.
Request Object
A request to invoke a method on the remote peer.
| Field | Type | Description | Required |
|---|
jsonrpc | string | Must be exactly "2.0". | Yes |
|---|
id | string number | A unique identifier for the request. | Yes |
|---|
method | string | The name of the method to be invoked. | Yes |
|---|
params | object array | Parameters for the method. Omit if none. | No |
|---|
Sent by the server in reply to a request.
| Field | Type | Description | Required |
|---|
jsonrpc | string | Must be exactly "2.0". | Yes |
|---|
id | string number null | Must match the id of the original request. | Yes |
|---|
result | any | The value returned by the method on success. | On Success |
|---|
error | object | An error object on failure. The result field MUST NOT exist if error exists. | On Error |
|---|
A request without an id field. The recipient MUST NOT reply.
| Field | Type | Description | Required |
|---|
jsonrpc | string | Must be exactly "2.0". | Yes |
|---|
method | string | The name of the method to be invoked. | Yes |
|---|
params | object array | Parameters for the method. Omit if none. | No |
|---|
MCP reserves method names prefixed with mcp/.
mcp/listTools: Lists all available tools.params:nullor{}result:ToolDefinition[]mcp/listResources: Lists all available resources.params:nullor{}result:ResourceDefinition[]mcp/listPrompts: Lists all available prompts.params:nullor{}result:PromptDefinition[]mcp/executeTool: Executes a specific tool.params:{ "id": string, "arguments": object }whereidis themcpIdof the tool andargumentsis an object matching the tool's input schema.result:{ "output": any }whereoutputmatches the tool's output schema.
Resource Schemas
All objects defined by an MCP server MUST include a unique mcpId. The mcpId should be a stable, namespaced URI.
ToolDefinition Schema
{
"type": "object",
"properties": {
"mcpId": {
"type": "string",
"description": "A unique, stable URI for this tool. E.g., 'mcp://acme-corp/tools/file-writer:v1'."
},
"name": {
"type": "string",
"description": "A short, descriptive, human-readable name for the tool."
},
"description": {
"type": "string",
"description": "A detailed explanation of what the tool does, its parameters, and its output."
},
"inputSchema": {
"type": "object",
"description": "A JSON Schema object defining the structure of the 'arguments' parameter for mcp/executeTool."
},
"outputSchema": {
"type": "object",
"description": "A JSON Schema object defining the structure of the 'output' field in the mcp/executeTool response."
}
},
"required": ["mcpId", "name", "description", "inputSchema", "outputSchema"]
}
ResourceDefinition Schema
Resources are static data assets, like configuration files or knowledge documents.
{
"type": "object",
"properties": {
"mcpId": {
"type": "string",
"description": "A unique, stable URI for this resource. E.g., 'mcp://my-server/resources/config.json'."
},
"name": {
"type": "string",
"description": "A short, descriptive, human-readable name for the resource."
},
"description": {
"type": "string",
"description": "A detailed explanation of the resource's purpose and content."
},
"mediaType": {
"type": "string",
"description": "The IANA media type of the resource content, e.g., 'application/json' or 'text/plain'."
},
"content": {
"type": "string",
"description": "The full content of the resource, encoded as a string."
}
},
"required": ["mcpId", "name", "description", "mediaType", "content"]
}
PromptDefinition Schema
Prompts are templates or instructions for an LLM.
{
"type": "object",
"properties": {
"mcpId": {
"type": "string",
"description": "A unique, stable URI for this prompt. E.g., 'mcp://my-prompts/system/planner-v2'."
},
"name": {
"type": "string",
"description": "A short, descriptive, human-readable name for the prompt."
},
"description": {
"type": "string",
"description": "A detailed explanation of the prompt's purpose and expected use."
},
"role": {
"type": "string",
"enum": ["system", "user", "assistant"],
"description": "The role associated with the prompt content."
},
"content": {
"type": "string",
"description": "The text content of the prompt."
}
},
"required": ["mcpId", "name", "role", "content"]
}
Error Handling
MCP uses standard JSON-RPC 2.0 error codes. Server implementations MUST return an error object for failed requests.
| Code | Message | Meaning |
|---|
| -32700 | Parse error | Invalid JSON was received by the server. |
|---|
| -32600 | Invalid Request | The JSON sent is not a valid Request object. |
|---|
| -32601 | Method not found | The method does not exist / is not available. |
|---|
| -32602 | Invalid Params | Invalid method parameters. |
|---|
| -32603 | Internal error | Internal JSON-RPC error. |
|---|
| -32000 | Execution Error | A tool-specific error occurred during execution. The data field SHOULD contain tool-specific error information. |
|---|
| -32001 | Resource Locked | The requested resource is locked or otherwise unavailable. Client may retry. |
|---|
| -32002 | Unauthorized | The client is not authorized to perform the requested operation. Credentials may be invalid or missing. |
|---|
MCP-specific error codes are in the range -32000 to -32099.
Examples
Example: Initialization Handshake (stdio)
A complete handshake over stdio.
Client sends to Server stdin:
Content-Length: 104\r\n
\r\n
{"jsonrpc":"2.0","method":"initialize","params":{"clientCapabilities":{}},"id":1}
Server writes to stdout:
Content-Length: 175\r\n
\r\n
{"jsonrpc":"2.0","id":1,"result":{"capabilities":{"listToolsProvider":true,"listResourcesProvider":false,"listPromptsProvider":false,"executionProvider":{"execute":true}}}}
Client sends to Server stdin:
Content-Length: 54\r\n
\r\n
{"jsonrpc":"2.0","method":"initialized","params":{}}
Example: Tool Execution Request (HTTP)
Client executes a tool named file-writer.
Client POST /mcp:
{
"jsonrpc": "2.0",
"method": "mcp/executeTool",
"params": {
"id": "mcp://acme-corp/tools/file-writer:v1",
"arguments": {
"path": "/home/agent/output.txt",
"content": "Hello, world."
}
},
"id": 2
}
Server responds:
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"output": {
"status": "success",
"bytesWritten": 13
}
}
}
Example: Invalid Params Error
Client omits a required argument for mcp/executeTool.
Client POST /mcp:
{
"jsonrpc": "2.0",
"method": "mcp/executeTool",
"params": {
"id": "mcp://acme-corp/tools/file-writer:v1",
"arguments": {
"path": "/home/agent/output.txt"
}
},
"id": 3
}
Server responds:
{
"jsonrpc": "2.0",
"id": 3,
"error": {
"code": -32602,
"message": "Invalid params",
"data": "Missing required property: 'content' in arguments for tool mcp://acme-corp/tools/file-writer:v1"
}
}
Anti-Patterns
- Using
stderrfor protocol messages. Do not do this.stderris for human-readable logs and diagnostics only. It will breakstdioparsers. - Responding to notifications. Do not send a response for a JSON-RPC message that has no
id. This violates the JSON-RPC spec. - Sending non-protocol data to
stdout. Do not print log messages or any other text tostdout. It must be used exclusively for framed JSON-RPC messages. - Assuming method availability. Do not call a method like
mcp/executeToolwithout first checking forexecutionProvider.execute: truein the server'scapabilityresponse during the handshake. - Using unstable
mcpIdvalues. Do not generatemcpIds dynamically per session. They must be stable identifiers that an agent can store and reference across sessions. - Returning
200 OKwith an error object. When using HTTP, if the JSON-RPC response contains anerrorobject, the HTTP status code should still be200 OK. The error is at the application layer, not the transport layer, unless the request itself was malformed (e.g., bad JSON, in which case a400 Bad Requestis appropriate).
Compliance Checklist
A compliant MCP v1.0 server implementation MUST:
- [ ] Correctly implement one or both of the specified transport layers (
stdioor HTTP). - [ ] If using
stdio, correctly frame allstdoutmessages withContent-Length. - [ ] Wait for the client's
initializerequest as the first message. - [ ] Respond to
initializewith aresultobject containing a validcapabilitiesobject. - [ ] Wait for the client's
initializednotification before sending any server-initiated notifications. - [ ] Implement all declared capabilities correctly (e.g., if
listToolsProvider: true, themcp/listToolsmethod must be implemented). - [ ] Adhere strictly to JSON-RPC 2.0 message formats for all requests, responses, and notifications.
- [ ] For any defined tool, resource, or prompt, provide a stable and unique
mcpId. - [ ] Provide valid JSON Schema for
inputSchemaandoutputSchemain allToolDefinitionobjects. - [ ] Return a JSON-RPC
errorobject for failed operations, using the specified error codes. - [ ] Not send any non-protocol data over the primary communication channel (
stdoutforstdio, the HTTP response body for HTTP).
Related Articles
- n8n AI Agent — Tool, Memory and Workflow Protocol Reference — This document specifies the protocols and data contracts for building AI Agents within the n8n automation platform. It provides a machine-readable reference for developers and autonomous agents on how to construct and interact with n8n Tool
- Pydantic AI — Dependency Injection and Tool Protocol Reference — This document specifies the protocol for defining and implementing tools for use with Pydantic AI agents. It details the contract for tool signatures, structured data handling, dependency injection via RunContext, and error handling semanti
- CrewAI — Agent, Task and Process Protocol Reference — This document specifies the definitive protocol for defining and executing Agent, Task, and Process interactions within the CrewAI framework. It is intended for developers of autonomous AI systems, integration tools, and monitoring services
- LiveKit Agents — Pipeline and Turn-Detection Protocol Reference — This document specifies the technical protocol for building agents that interoperate with the LiveKit Agents framework. It defines the lifecycle, state transitions, communication patterns, and data structures that an agent implementation mu
- MCP Server Implementation Guide: Best Practices for Tool Integration — Build robust MCP servers for agents. Learn schemas, idempotency, streaming, scopes, and observability to support GPT-5, Claude 4, and Gemini 3. Implement now.