- Home
- MCP servers
- MCP Chain
MCP Chain
- python
7
GitHub Stars
python
Language
5 months ago
First Indexed
2 months ago
Catalog Refreshed
Documentation & install
Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.
Installation
Add the following to your MCP client configuration file.
Configuration
View docs{
"mcpServers": {
"ruliana-mcp-chain": {
"command": "uvx",
"args": [
"mcp-chain",
"cli_server.py"
]
}
}
}You learn to compose MCP servers into a chain of middlewares that transparently proxy requests, transform data, and orchestrate downstream MCP servers. This lets you add authentication, logging, and request transformations without modifying existing MCP servers, while enabling multi-step tasks through a programmable chain.
How to use
You use the MCP chain by creating a chain object and attaching middleware and downstream MCP servers. Each middleware can inspect and modify requests or metadata, then forward to the next layer. You can expose command-line tools as an MCP server, add authentication, log requests, and transform responses, all without changing the downstream servers.
How to install
Prerequisites: you need Python and a compatible runtime. You also install and run the MCP chain with the included tooling.
# cli_server.py
from mcp_chain import mcp_chain, CLIMCPServer
cli_server = CLIMCPServer(
name="dev_tools",
commands=["git", "ls", "grep"],
descriptions={
"git": "Git version control operations",
"ls": "List directory contents",
"grep": "Search text patterns"
}
)
# Auto-detected by CLI
chain = mcp_chain().then(cli_server)
uvx mcp-chain cli_server.py
Configuration and examples
{
"mcpServers": {
"dev_tools": {
"command": "uvx",
"args": ["mcp-chain", "cli_server.py"]
}
}
}
Additional sections
The MCP Chain supports multiple middleware layers that can be stacked to create complex behavior. You can implement authentication, metadata enrichment, and request/response transformations. You can also route to an external MCP server or expose a local CLI-based server.
Troubleshooting and notes
If a middleware does not appear to influence requests, verify that it forwards the request to the next layer and that each layer returns the transformed response back up the chain. Ensure that every URL or runtime command you configure is explicitly provided in code blocks or configuration examples and that any required environment variables are defined in the environment you run.
Available tools
mcp_chain
Creates a chain object to compose middleware layers and downstream MCP servers.
CLIMCPServer
Exposes command-line tools as an MCP server with a CLI interface.
ExternalMCPServer
Proxies requests to an external MCP server and participates in the chain.
serve
Runs the composed chain as an MCP server with a given name and port.
require_auth
Middleware function that enforces authentication on incoming requests.
add_company_context
Middleware that enriches metadata with company-specific descriptions.
add_headers
Middleware that injects headers into requests and annotates responses.
auth_middleware
Authentication middleware example used in multi-middleware chains.
logging_middleware
Middleware that logs requests and responses for observability.
context_middleware
Middleware that enriches metadata with contextual information.
rate_limit_middleware
Middleware placeholder for implementing rate limiting on requests.