MCP API Reference
Complete API documentation for the Model Context Protocol
The Model Context Protocol (MCP) provides a standardized way for AI assistants to communicate with external tools and data sources. This API reference covers the core concepts, endpoints, and implementation details.
Server Endpoints
Standardized endpoints that MCP servers must implement
Client Integration
How to integrate MCP servers with AI clients
MCP Server
An MCP server is a process that implements the MCP protocol and provides specific functionality to AI assistants. Servers can handle file operations, database queries, web searches, and more.
// Example server configuration
{
"name": "filesystem",
"version": "1.0.0",
"description": "File system operations",
"capabilities": {
"tools": ["read_file", "write_file", "list_directory"]
}
}
MCP Client
An MCP client is an AI assistant or application that connects to MCP servers to access their capabilities. Clients communicate with servers using the standardized MCP protocol.
// Example client configuration
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["@mcp/server-filesystem"],
"env": {
"MCP_FILESYSTEM_ROOT": "/path/to/root"
}
}
}
}
Tools and Resources
MCP servers expose two main types of capabilities: tools (for actions) and resources (for data access). Tools perform operations, while resources provide read access to data.
Tools
Functions that perform actions like file operations, API calls, etc.
Resources
Data sources that can be read, like files, databases, etc.
/initialize
Initialize the MCP server and establish the connection
Request: { protocol_version, capabilities, client_info }
/tools/list
List all available tools provided by the server
Response: { tools: [Tool] }
/tools/call
Execute a specific tool with provided arguments
Request: { name, arguments }
/resources/list
List all available resources provided by the server
Response: { resources: [Resource] }
/resources/read
Read data from a specific resource
Request: { uri, mimeType }
Creating an MCP Server
To create an MCP server, you need to implement the standard MCP protocol endpoints and handle the communication with clients.
// Basic server structure
class MCPServer {
async initialize(request) {
return {
protocol_version: "2024-11-05",
capabilities: {
tools: [...],
resources: [...]
}
};
}
async listTools() {
return { tools: [...] };
}
async callTool(name, arguments) {
// Implement tool logic
}
}
Error Handling
Proper error handling is crucial for MCP servers. Always return structured error responses with appropriate error codes and messages.
// Error response format
{
"error": {
"kind": "invalid_request",
"message": "Invalid tool name provided",
"data": { "tool_name": "unknown_tool" }
}
}