> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-ai/boxlang-ai/mcp.md).

# MCP

Consume tools from any MCP server, expose your own tools as an MCP server, and give agents live access to a running BoxLang runtime.

The **Model Context Protocol (MCP)** is an open standard that lets AI applications connect to tools, resources, and prompts. BoxLang AI supports it in both directions.

```mermaid
flowchart LR
    subgraph Your App
        Agent[Agent]
        Client[MCP Client]
        Server[MCP Server]
        Tools[Your Tools]
    end
    Client -->|consume| External[External MCP Servers]
    Agent --> Client
    Tools --> Server
    Server -->|expose| Others[Claude, IDEs, other agents]
```

## 📥 MCP Client: Consume Tools

Connect to any MCP server and call its tools:

```js
client = MCP( "http://localhost:3000" )

result = client.send( "searchDocs", {
    query: "BoxLang syntax",
    limit: 10
} )

if ( result.getSuccess() ) {
    println( result.getData() )
}
```

Or seed an agent with an MCP server's tools:

```js
agent = aiAgent(
    name: "ResearchAgent",
    mcpServers: [
        {
            url: "http://localhost:3000/mcp",
            toolNames: [ "web_search", "fetch_page" ]
        }
    ]
)
```

## 📤 MCP Server: Expose Your Tools

Register tools when your application starts:

```js
// Application.bx
class {

    function onApplicationStart() {
        MCPServer( "myApp" )
            .setDescription( "My Application MCP Server" )
            .setVersion( "1.0.0" )
            .registerTool(
                aiTool( "search", "Search for documents", ( query ) => {
                    return searchService.search( query )
                } )
            )
    }

}
```

The module provides an HTTP endpoint, so any MCP client can list and call your tools:

```bash
curl -X POST "http://localhost/~bxai/mcp.bxm?server=myApp" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"tools/list","id":"1"}'
```

Servers can also register resources and prompts, discover tools from annotations, run over HTTP or STDIO, and be built as classes.

## 🔍 Live Runtime Introspection With MCP +

The BoxLang+ [**MCP +**](/boxlang-+-++/modules/bx-mcp.md) module is a ready-made MCP server for a **running BoxLang runtime**. Agents and monitoring tools can inspect JVM health, caches, datasources, HTTP traffic, schedulers, and modules, with bearer tokens, security profiles, and IP allowlists for governance.

{% hint style="success" %}
**Try every BoxLang+ module free for 60 days.** The trial starts automatically with no sign-up and no key. See [BoxLang MCP](/getting-started/agentic-development/boxlang-mcp.md).
{% endhint %}

## 🧱 ColdBox

ColdBox routes can expose agents and MCP servers directly with `toAi()` and `toMCP()`, and the `cbMCP` module lets agents introspect a running ColdBox application. See [Agentic MVC with ColdBox](https://coldbox.ortusbooks.com/getting-started/agentic-development).

## 🔍 Go Deeper

* [MCP Servers](https://ai.ortusbooks.com/model-context-protocol-mcp/server)
* [Getting Started with MCP Servers](https://ai.ortusbooks.com/model-context-protocol-mcp/server/getting-started)
* [Transports (HTTP and STDIO)](https://ai.ortusbooks.com/model-context-protocol-mcp/server/transports)
* [MCP Clients](https://ai.ortusbooks.com/model-context-protocol-mcp/client)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-ai/boxlang-ai/mcp.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
