Model Control Protocol (MCP) allows you to integrate external tool providers with your Chainlit application. This enables your AI models to use tools through standardized interfaces.
MCP provides a mechanism for Chainlit applications to connect to either server-sent events (SSE) based services or command-line (stdio) based tools. Once connected, your application can discover available tools, execute them, and integrate their responses into your application’s flow.
End to end cookbook example showcasing MCP tool calling with Claude.
Connect to an MCP server
We’re working with companies to create their MCP stacks, enabling AI agents to consume their data and context in standardized ways. Fill out this form.
Chainlit supports two types of MCP connections:
⚠️ Security Warning: The stdio connection type spawns actual subprocesses on the Chainlit server. Only use this with trusted commands in controlled environments. Ensure proper validation of user inputs to prevent command injection vulnerabilities.
npx
or uvx
, these commands must be available on the Chainlit server where the application is running. The subprocess is executed on the server, not on the client machine.config.toml
)You can control which MCP connection types are enabled globally and restrict allowed stdio commands by modifying your project’s config.toml
file (usually located at the root of your project or .chainlit/config.toml
).
Under the [features.mcp]
section, you can configure SSE and stdio separately:
To use MCP in your Chainlit application, you need to implement the on_mcp_connect
handler. The on_mcp_disconnect
handler is optional but recommended for proper cleanup.
The client needs to provide the connection details through the Chainlit interface. This includes:
sse
or stdio
)npx your-tool-package
or uvx your-tool-package
)Adding an MCP
Upon connection, you can discover the available tools provided by the MCP service:
You can execute tools using the MCP session:
MCP tools can be seamlessly integrated with LLMs that support tool calling:
MCP connections are managed at the session level. Each WebSocket session can have multiple named MCP connections. The connections are cleaned up when:
Model Control Protocol (MCP) allows you to integrate external tool providers with your Chainlit application. This enables your AI models to use tools through standardized interfaces.
MCP provides a mechanism for Chainlit applications to connect to either server-sent events (SSE) based services or command-line (stdio) based tools. Once connected, your application can discover available tools, execute them, and integrate their responses into your application’s flow.
End to end cookbook example showcasing MCP tool calling with Claude.
Connect to an MCP server
We’re working with companies to create their MCP stacks, enabling AI agents to consume their data and context in standardized ways. Fill out this form.
Chainlit supports two types of MCP connections:
⚠️ Security Warning: The stdio connection type spawns actual subprocesses on the Chainlit server. Only use this with trusted commands in controlled environments. Ensure proper validation of user inputs to prevent command injection vulnerabilities.
npx
or uvx
, these commands must be available on the Chainlit server where the application is running. The subprocess is executed on the server, not on the client machine.config.toml
)You can control which MCP connection types are enabled globally and restrict allowed stdio commands by modifying your project’s config.toml
file (usually located at the root of your project or .chainlit/config.toml
).
Under the [features.mcp]
section, you can configure SSE and stdio separately:
To use MCP in your Chainlit application, you need to implement the on_mcp_connect
handler. The on_mcp_disconnect
handler is optional but recommended for proper cleanup.
The client needs to provide the connection details through the Chainlit interface. This includes:
sse
or stdio
)npx your-tool-package
or uvx your-tool-package
)Adding an MCP
Upon connection, you can discover the available tools provided by the MCP service:
You can execute tools using the MCP session:
MCP tools can be seamlessly integrated with LLMs that support tool calling:
MCP connections are managed at the session level. Each WebSocket session can have multiple named MCP connections. The connections are cleaned up when: