Files
gh-rafaelcalleja-claude-mar…/skills/mcp-management/references/mcp-protocol.md
2025-11-30 08:48:52 +08:00

2.2 KiB

Model Context Protocol (MCP) Reference

Protocol Overview

MCP is JSON-RPC 2.0 based protocol for AI-tool integration.

Version: 2025-03-26 Foundation: JSON-RPC 2.0 Architecture: Client-Host-Server

Connection Lifecycle

  1. Initialize: Client sends initialize request with capabilities
  2. Response: Server responds with its capabilities
  3. Handshake: Client sends notifications/initialized
  4. Active: Bidirectional messaging
  5. Shutdown: Close connections, cleanup

Core Capabilities

Tools (Executable Functions)

Tools are functions that servers expose for execution.

List Tools:

{"method": "tools/list"}

Call Tool:

{
  "method": "tools/call",
  "params": {
    "name": "tool_name",
    "arguments": {}
  }
}

Prompts (Interaction Templates)

Prompts are reusable templates for LLM interactions.

List Prompts:

{"method": "prompts/list"}

Get Prompt:

{
  "method": "prompts/get",
  "params": {
    "name": "prompt_name",
    "arguments": {}
  }
}

Resources (Data Sources)

Resources expose read-only data to clients.

List Resources:

{"method": "resources/list"}

Read Resource:

{
  "method": "resources/read",
  "params": {"uri": "resource://path"}
}

Transport Types

stdio (Local)

Server runs as subprocess. Messages via stdin/stdout.

const transport = new StdioClientTransport({
  command: 'node',
  args: ['server.js']
});

HTTP+SSE (Remote)

POST for requests, GET for server events.

const transport = new StreamableHTTPClientTransport({
  url: 'http://localhost:3000/mcp'
});

Error Codes

  • -32700: Parse error
  • -32600: Invalid request
  • -32601: Method not found
  • -32602: Invalid params
  • -32603: Internal error
  • -32002: Resource not found (MCP-specific)

Best Practices

  1. Progressive Disclosure: Load tool definitions on-demand
  2. Context Efficiency: Filter data before returning
  3. Security: Validate inputs, sanitize outputs
  4. Resource Management: Cleanup connections properly
  5. Error Handling: Handle all error cases gracefully