Skip to content

Commit 607cf1f

Browse files
authored
Merge pull request modelcontextprotocol#41 from modelcontextprotocol/davidsp/missing-docs
feat: Add protocol details for error codes, pagination, and templates
2 parents b5a0305 + f2ab31c commit 607cf1f

File tree

3 files changed

+150
-1
lines changed

3 files changed

+150
-1
lines changed

docs/spec/_index.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,36 @@ In addition to basic primitives, MCP offers a set of control flow messages.
5050
* **Logging:** Anything related to how the server processes logs.
5151
* **Completion**: Supports completion of server arguments on the client side. See
5252

53+
## Error Codes
54+
55+
MCP uses standard JSON-RPC error codes as well as protocol-specific codes:
56+
57+
Standard JSON-RPC error codes:
58+
- `-32700`: Parse error
59+
- `-32600`: Invalid request
60+
- `-32601`: Method not found
61+
- `-32602`: Invalid params
62+
- `-32603`: Internal error
63+
64+
All error responses MUST include:
65+
- A numeric error code
66+
- A human-readable message
67+
- Optional additional error data
68+
69+
Example error response:
70+
```json
71+
{
72+
"jsonrpc": "2.0",
73+
"id": 1,
74+
"error": {
75+
"code": -32602,
76+
"message": "Required parameter missing",
77+
"data": {
78+
"parameter": "uri"
79+
}
80+
}
81+
}
82+
```
5383
# Use cases
5484
Most use cases are around enabling people to build their own specific workflows and integrations. MCP enables engineers and teams to **tailor AI to their needs.**
5585

docs/spec/jsonrpc.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,71 @@ HTTP with Server-Sent Events (SSE)
2626

2727
### Message Format
2828

29+
### Progress Notifications
30+
31+
MCP supports progress tracking for long-running operations through out-of-band notifications. Progress notifications allow the sender of a request to provide updates about the operation's progress.
32+
33+
To request progress notifications, include a `progressToken` in the request metadata:
34+
35+
```json
36+
{
37+
"jsonrpc": "2.0",
38+
"id": 1,
39+
"method": "some_method",
40+
"params": {
41+
"_meta": {
42+
"progressToken": "abc123"
43+
}
44+
}
45+
}
46+
```
47+
48+
The receiver MAY then send progress notifications using the same token:
49+
50+
```json
51+
{
52+
"jsonrpc": "2.0",
53+
"method": "notifications/progress",
54+
"params": {
55+
"progressToken": "abc123",
56+
"progress": 50,
57+
"total": 100
58+
}
59+
}
60+
```
61+
62+
### Pagination
63+
64+
Many list operations in MCP support pagination using cursors. The server response will include a `nextCursor` if more results are available:
65+
66+
```json
67+
{
68+
"jsonrpc": "2.0",
69+
"id": 1,
70+
"result": {
71+
"resources": [...],
72+
"nextCursor": "next_page_token"
73+
}
74+
}
75+
```
76+
77+
Clients can include a `cursor` parameter containing the opaque token from the server,
78+
to obtain the next page starting from the cursor:
79+
80+
```json
81+
{
82+
"jsonrpc": "2.0",
83+
"id": 1,
84+
"method": "resources/list",
85+
"params": {
86+
"cursor": "some_opaque_token"
87+
}
88+
}
89+
```
90+
91+
92+
Clients should continue making requests with the provided cursor until no `nextCursor` is returned.
93+
2994
All messages in MCP **MUST** follow the [JSON-RPC 2.0](https://www.jsonrpc.org/specification) specification. The protocol defines three types of messages:
3095

3196
1. Requests
@@ -73,6 +138,30 @@ Authentication mechanisms are not part of the core MCP specification. Implementa
73138

74139
The MCP version is declared in the `initialize` request and response. Clients and servers **MUST** agree on a compatible protocol version to proceed with communication.
75140

141+
### Ping Messages
142+
143+
Either party can send ping messages to check if the other is still alive and responsive:
144+
145+
```json
146+
{
147+
"jsonrpc": "2.0",
148+
"id": 1,
149+
"method": "ping"
150+
}
151+
```
152+
153+
The receiver MUST respond promptly with an empty result:
154+
155+
```json
156+
{
157+
"jsonrpc": "2.0",
158+
"id": 1,
159+
"result": {}
160+
}
161+
```
162+
163+
If the receiver fails to respond in a timely manner, the sender MAY disconnect.
164+
76165
## Specification
77166

78167
The conical specification can be found at [Model Context Protocol](http://github.com/modelcontextprotocol/spec/tree/main/spec/schema.ts). The specification of the data format

docs/spec/resources.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,36 @@ In this example, the server supports basic resource operations, subscriptions, a
4343
A Resource in the Model Context Protocol (MCP) represents a discrete unit of data that a server can provide to clients. Each Resource is uniquely identified by a URI and may have associated metadata such as a name and MIME type. Resources can represent various types of data, including files, database records, or application-specific information.
4444

4545
### Resource Templates
46+
To retrieve available resource templates from the server, the client MUST send a `resources/templates/list` request:
47+
48+
```json
49+
{
50+
"jsonrpc": "2.0",
51+
"id": 1,
52+
"method": "resources/templates/list"
53+
}
54+
```
55+
56+
The server MUST respond with a list of resource templates:
57+
58+
```json
59+
{
60+
"jsonrpc": "2.0",
61+
"id": 1,
62+
"result": {
63+
"resourceTemplates": [
64+
{
65+
"uriTemplate": "file:///{path}",
66+
"name": "Local File",
67+
"description": "Access local files",
68+
"mimeType": "application/octet-stream"
69+
}
70+
]
71+
}
72+
}
73+
```
74+
75+
Resource templates use URI templates as defined in [RFC 6570](https://datatracker.ietf.org/doc/html/rfc6570) to specify parameterized resource URIs.
4676

4777
Resource Templates are URI patterns that describe a class of resources that can be dynamically generated or accessed. They use URI templates as defined in [RFC 6570](https://datatracker.ietf.org/doc/html/rfc6570) to specify how clients can construct valid resource URIs. Templates allow servers to expose a potentially large or dynamic set of resources without explicitly listing each one. Clients can use these templates to generate specific resource URIs as needed.
4878

@@ -159,7 +189,7 @@ Example:
159189
"result": {
160190
"resourceTemplates": [
161191
{
162-
"uriTemplate": "file://{path}",
192+
"uriTemplate": "file:///{path}",
163193
"name": "Local File",
164194
"description": "Access local files",
165195
"mimeType": "application/octet-stream"

0 commit comments

Comments
 (0)