# Model Context Protocol (MCP)

The PureCode AI Extension has significantly enhanced its capabilities by introducing support for the Model Context Protocol (MCP). This integration allows users to connect to a diverse range of backend services, which can include local binaries, applications running within Docker containers, or remote HTTP services.

> Connect your PureCode AI Extension to diverse backends—local binaries, Docker containers, and remote services—using a simple, extensible JSON configuration format.

<figure><img src="/files/P7wQvybX3hZW1zbcSMPv" alt=""><figcaption></figcaption></figure>

<table data-view="cards"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>Flexible Configuration</strong></td><td>JSON-based format supporting multiple servers with stdio and SSE transport protocols.</td></tr><tr><td><strong>Automatic Discovery</strong></td><td>Tools are automatically detected and made available in the sidebar with real-time status.</td></tr><tr><td>Extensive Architecture</td><td>Add new MCP servers without code changes—simply update your configuration.</td></tr></tbody></table>

### What is MCP?

The **Model Context Protocol (MCP)** is an open protocol designed to standardize how applications provide context, data sources, and tools to Large Language Models (LLMs). Think of MCP as a universal adapter, much like a USB-C port for AI applications.&#x20;

### Key Benefits

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>Plug-and-Play Extensibility</strong></td><td>Users can effortlessly add, remove, or swap out MCP servers by making simple changes to a configuration file or through the user interface. New MCP-compatible tools can be integrated without requiring updates to the core extension.</td></tr><tr><td><strong>Unified User Experience</strong></td><td>Regardless of the underlying backend, all tools exposed via MCP servers appear and behave consistently within the PureCode AI Extension's UI, reducing learning curves and streamlining workflows.</td></tr></tbody></table>

### Configuring MCP Servers

Configuring MCP servers involves defining them in a structured JSON format. The configuration file serves as the central point for managing all MCP servers accessible to the PureCode AI Extension.

Basic Configuration Structure :

{% code overflow="wrap" %}

```json
{
  "mcpServers": {
    "your-server-id": {
      "name": "Server Name",
      "id": "your-server-id",
      "transport": {
        "type": "stdio|sse",
        // For stdio transport:
        "command": "npx|docker|node",
        "args": ["-y", "package-name", "--optional-flag"],
        "env": {
          "API_KEY": "your_api_key"
        }
        // For SSE transport:
        // "url": "https://your-server.com/sse"
      },
      "enabled": true
    }
  }
}
```

{% endcode %}

### Transport Mechanisms

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><strong>stdio (Standard Input/Output)</strong></td><td>Used for MCP servers launched as local processes. The extension starts the process and communicates via stdin/stdout.</td><td><strong>Fields:</strong> command, args, env (optional)</td></tr><tr><td>sse (Server-Sent Events)</td><td>Used for MCP servers exposing HTTP endpoints. The extension connects to the URL and receives real-time updates.</td><td><strong>Field:</strong> url</td></tr></tbody></table>

{% hint style="info" %}
**Securing Credentials**

Use the `env` object to securely pass API keys and tokens without hardcoding them in configuration files. This prevents accidental exposure in version control systems.
{% endhint %}

### Key Configuration Fields

| Field     | Description                           | Required | Example                  |
| --------- | ------------------------------------- | -------- | ------------------------ |
| name      | Human-readable name for display in UI | Yes      | "Filesystem Indexer"     |
| id        | Unique identifier for the server      | Yes      | "file-system"            |
| transport | Connection protocol and parameters    | Yes      | { "type": "stdio", ... } |

### Technical Details and Advanced Features

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>Automatic Discovery</strong></td><td>The extension automatically parses the mcpServers configuration, establishes connections, and queries each server for available tools. This happens transparently during startup or configuration reload.</td></tr><tr><td><strong>Extensible Transport Layer</strong></td><td>The architecture supports multiple transport mechanisms (stdio, SSE) and is designed to accommodate future protocols without fundamental changes to the core extension.</td></tr><tr><td><strong>Seamless Integration</strong></td><td>MCP-enabled tools are indistinguishable from native tools in the user interface. The AI can autonomously invoke these tools when appropriate to fulfill user requests.</td></tr><tr><td><strong>Deployment Flexibility</strong></td><td>Comprehensive support for local processes, Docker containers, and remote HTTP services ensures users can choose the deployment model that best fits their needs.</td></tr></tbody></table>

### Supported Deployment Models

<table data-view="cards"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>Local Processes</strong></td><td>Run directly on your machine using stdio transport</td></tr><tr><td><strong>Docker Containers</strong></td><td>Isolated, consistent execution environments</td></tr><tr><td><strong>Remote Services</strong></td><td>Connect to HTTP endpoints via SSE transport</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://purecodedocs.gitbook.io/docs/features/model-context-protocol-mcp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
