agentgrade

← Knowledge Base

What is MCP?

MCP (Model Context Protocol) is how AI assistants like Claude and ChatGPT call external tools. Your server exposes "tools" — functions with names, descriptions, and input schemas — and the AI model decides when to call them during a conversation.

How it works

All communication uses JSON-RPC 2.0 over HTTP POST to a single endpoint (e.g., /mcp):

  • Client sends initialize to establish the session
  • Server responds with its name, version, and capabilities
  • Client sends tools/list to discover available tools
  • Server returns a list of tools with descriptions and input schemas
  • Client sends tools/call with a tool name and arguments
  • Server executes the tool and returns the result
  • Implementation example

    app.post('/mcp', (req, res) => {
      const { method, params, id } = req.body;
    
      if (method === 'initialize') {
        return res.json({ jsonrpc: '2.0', id, result: {
          protocolVersion: '2024-11-05',
          capabilities: { tools: {} },
          serverInfo: { name: 'my-service', version: '1.0' }
        }});
      }
    
      if (method === 'tools/list') {
        return res.json({ jsonrpc: '2.0', id, result: {
          tools: [{
            name: 'search',
            description: 'Search for items',
            inputSchema: {
              type: 'object',
              properties: { query: { type: 'string' } },
              required: ['query']
            }
          }]
        }});
      }
    
      if (method === 'tools/call') {
        const { name, arguments: args } = params;
        return res.json({ jsonrpc: '2.0', id, result: {
          content: [{ type: 'text', text: 'Search results...' }]
        }});
      }
    
      res.json({ jsonrpc: '2.0', id, error: { code: -32601, message: 'Method not found' }});
    });
    

    Key concepts

    Spec maturity

    Formal specification. MCP is maintained by Anthropic with a versioned spec. Current protocol version: 2024-11-05. Supported natively by Claude, ChatGPT, and many AI tools.

    Learn more