Understanding the Model Context Protocol (MCP)

Exploration of what MCP is, how it works, and design decisions behind it

This document explores the Model Context Protocol (MCP), how it works, the design decisions behind it, and how it compares to alternative approaches for LLM tool integration.

What is the Model Context Protocol?

The Model Context Protocol (MCP) is a standardized communication protocol that enables Large Language Models (LLMs) to interact with external tools and capabilities. It defines a structured way for models to request information or take actions in the real world, and for tools to provide responses back to the model.

MCP is designed to solve the problem of extending LLMs beyond their training data by giving them access to:

  • Current information (e.g., via web search)
  • Computational capabilities (e.g., calculators, code execution)
  • External systems (e.g., databases, APIs)
  • User environment (e.g., file system, terminal)

How MCP Works

At its core, MCP is a protocol based on JSON-RPC that enables bidirectional communication between LLMs and tools. The basic workflow is:

  1. The LLM generates a call to a tool with specific parameters
  2. The host intercepts this call and routes it to the appropriate tool
  3. The tool executes the requested action and returns the result
  4. The result is injected into the model’s context
  5. The model continues generating a response incorporating the new information

The protocol specifies:

  • How tools declare their capabilities and parameters
  • How the model requests tool actions
  • How tools return results or errors
  • How multiple tools can be combined

MCP in gomcptest

In gomcptest, MCP is implemented using a set of independent executables that communicate over standard I/O. This approach has several advantages:

  • Language-agnostic: Tools can be written in any programming language
  • Process isolation: Each tool runs in its own process for security and stability
  • Compatibility: The protocol works with various LLM providers
  • Extensibility: New tools can be easily added to the system

Each tool in gomcptest follows a consistent pattern:

  1. It receives a JSON request on stdin
  2. It parses the parameters and performs its action
  3. It formats the result as JSON and returns it on stdout

The Protocol Specification

The core MCP protocol in gomcptest follows this format:

Tool Registration

Tools register themselves with a schema that defines their capabilities:

{
  "name": "ToolName",
  "description": "Description of what the tool does",
  "parameters": {
    "type": "object",
    "properties": {
      "param1": {
        "type": "string",
        "description": "Description of parameter 1"
      },
      "param2": {
        "type": "number",
        "description": "Description of parameter 2"
      }
    },
    "required": ["param1"]
  }
}

Function Call Request

When a model wants to use a tool, it generates a function call like:

{
  "name": "ToolName",
  "params": {
    "param1": "value1",
    "param2": 42
  }
}

Function Call Response

The tool executes the requested action and returns:

{
  "result": "Output of the tool's execution"
}

Or, in case of an error:

{
  "error": {
    "message": "Error message",
    "code": "ERROR_CODE"
  }
}

Design Decisions in MCP

Several key design decisions shape the MCP implementation in gomcptest:

Standard I/O Communication

By using stdin/stdout for communication, tools can be written in any language that can read from stdin and write to stdout. This makes it easy to integrate existing utilities and libraries.

JSON Schema for Tool Definition

Using JSON Schema for tool definitions provides a clear contract between the model and the tools. It enables:

  • Validation of parameters
  • Documentation of capabilities
  • Potential for automatic code generation

Stateless Design

Tools are designed to be stateless, with each invocation being independent. This simplifies the protocol and makes tools easier to reason about and test.

Pass-through Authentication

The protocol doesn’t handle authentication directly; instead, it relies on the host to manage permissions and authentication. This separation of concerns keeps the protocol simple.

Comparison with Alternatives

vs. OpenAI Function Calling

MCP is similar to OpenAI’s function calling feature but with these key differences:

  • MCP is designed to be provider-agnostic
  • MCP tools run as separate processes
  • MCP provides more detailed error handling

vs. LangChain Tools

Compared to LangChain:

  • MCP is a lower-level protocol rather than a framework
  • MCP focuses on interoperability rather than abstraction
  • MCP allows for stronger process isolation

vs. Agent Protocols

Other agent protocols often focus on higher-level concepts like goals and planning, while MCP focuses specifically on the mechanics of tool invocation.

Future Directions

The MCP protocol in gomcptest could evolve in several ways:

  • Enhanced security: More granular permissions and sand-boxing
  • Streaming responses: Support for tools that produce incremental results
  • Bidirectional communication: Supporting tools that can request clarification
  • Tool composition: First-class support for chaining tools together
  • State management: Optional session state for tools that need to maintain context

Conclusion

The Model Context Protocol as implemented in gomcptest represents a pragmatic approach to extending LLM capabilities through external tools. Its simplicity, extensibility, and focus on interoperability make it a solid foundation for building and experimenting with agentic systems.

By understanding the protocol, developers can create new tools that seamlessly integrate with the system, unlocking new capabilities for LLM applications.


Last modified March 18, 2025: wip (3f09032)