Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/mcp-use/mcp-use/llms.txt

Use this file to discover all available pages before exploring further.

What is the Model Context Protocol?

The Model Context Protocol (MCP) is an open standard that enables AI applications to securely connect to external data sources and tools. It provides a universal way for AI models to interact with the outside world through a standardized interface.
Think of MCP as “USB for AI” - a universal connector that lets AI models plug into any tool or data source through a common protocol.

Why MCP Matters

Traditional AI integrations require custom code for each tool or data source. MCP solves this by:

Universal Standard

One protocol to connect AI models to any tool, API, or data source

Security First

Built-in authentication, authorization, and sandboxed execution

Composability

Mix and match tools from different providers seamlessly

Future-Proof

Open standard that evolves with the AI ecosystem

Core Architecture

MCP follows a client-server architecture:

Components

MCP Client is the component that AI applications use to connect to MCP servers.The client:
  • Discovers available tools and resources from servers
  • Manages connections to multiple servers simultaneously
  • Routes tool calls to the appropriate server
  • Handles authentication and session management
Example:
import { MCPClient } from "mcp-use";

const client = MCPClient.fromDict({
  mcpServers: {
    filesystem: {
      command: "npx",
      args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
    }
  }
});

MCP Protocol Flow

Here’s how a typical MCP interaction works:
1

Initialization

The client connects to the server and exchanges capabilities.
{
  "jsonrpc": "2.0",
  "method": "initialize",
  "params": {
    "protocolVersion": "2024-11-05",
    "capabilities": {}
  }
}
2

Discovery

The client discovers available tools, resources, and prompts.
const tools = await session.listTools();
console.log(tools);
// [
//   { name: "search_web", description: "Search the web" },
//   { name: "read_file", description: "Read a file" }
// ]
3

Execution

The AI model decides which tool to call and provides arguments.
{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "name": "search_web",
    "arguments": {
      "query": "MCP protocol"
    }
  }
}
4

Response

The server executes the tool and returns results.
{
  "jsonrpc": "2.0",
  "result": {
    "content": [
      {
        "type": "text",
        "text": "Found 10 results for MCP protocol..."
      }
    ]
  }
}

Protocol Specification

MCP is built on JSON-RPC 2.0 with specific message types:

Message Types

Tools are functions that AI models can call to perform actions.
// Server side
server.tool({
  name: "calculate",
  description: "Perform calculations",
  schema: z.object({
    expression: z.string(),
  }),
}, async ({ expression }) => {
  const result = eval(expression);
  return text(`Result: ${result}`);
});

// Client side
const result = await session.callTool("calculate", {
  expression: "2 + 2"
});

Advanced Features

Progress Notifications

Servers can send progress updates during long-running operations:
server.tool({
  name: "process-large-file",
  schema: z.object({ file: z.string() }),
}, async ({ file }, { progress }) => {
  progress?.({ progress: 0, total: 100 });
  
  // ... processing ...
  
  progress?.({ progress: 50, total: 100 });
  
  // ... more processing ...
  
  progress?.({ progress: 100, total: 100 });
  return text("Done!");
});

Logging

Servers can emit structured logs:
server.on("logging/setLevel", async (level) => {
  console.log(`Log level set to: ${level}`);
});

// Emit logs
server.log("info", "Processing started");
server.log("debug", "Detailed information", { extra: "data" });

Authentication

MCP supports OAuth and custom authentication:
const server = new MCPServer({
  name: "secure-server",
  version: "1.0.0",
  oauth: {
    clientId: process.env.OAUTH_CLIENT_ID,
    clientSecret: process.env.OAUTH_CLIENT_SECRET,
    authorizationUrl: "https://oauth.example.com/authorize",
    tokenUrl: "https://oauth.example.com/token",
  },
});

Protocol Versions

mcp-use supports the latest MCP protocol version:
  • Current: 2024-11-05
  • Features: Tools, Resources, Prompts, Sampling, Roots, Authentication
  • Transports: stdio, HTTP/SSE, WebSocket
mcp-use automatically negotiates the protocol version with servers, so you don’t need to worry about version compatibility.

Standards Compliance

mcp-use is fully compliant with the official MCP specification:
FeatureTypeScriptPython
Tools
Resources
Prompts
Sampling
Roots
Authentication
stdio Transport
HTTP/SSE Transport
WebSocket Transport

Learn More

Official MCP Spec

Read the official Model Context Protocol specification

MCP Servers

Understand the difference between MCP Servers and Apps

Tools, Resources, Prompts

Deep dive into MCP primitives

Architecture

Learn about mcp-use architecture

Build docs developers (and LLMs) love