thulp-mcp
Model Context Protocol (MCP) Integration for Thulp
This crate provides transport implementations for connecting to MCP servers using the Model Context Protocol. It wraps rs-utcp to provide a Thulp-native interface for MCP tool discovery and execution.
Features
- STDIO Transport: Spawn and communicate with local MCP servers via standard input/output
- HTTPS Transport: Connect to remote MCP servers over HTTPS
- Tool Discovery: Automatic conversion from MCP JSON Schema to Thulp
ToolDefinition - Tool Execution: Call MCP tools with parameter validation
- Connection Management: Handle server lifecycle (connect, disconnect, reconnect)
- Error Handling: Rich error types for transport and protocol errors
Installation
Add to your Cargo.toml:
[]
= "0.2"
For Ares server support:
[]
= { = "0.2", = ["ares"] }
Usage
Connecting via STDIO
Connect to a local MCP server using standard input/output:
use McpTransport;
async
Connecting via HTTPS
Connect to a remote MCP server over HTTPS:
use McpTransport;
async
Listing Available Tools
Discover tools provided by the MCP server:
use McpTransport;
async
Calling a Tool
Execute an MCP tool with parameters:
use McpTransport;
use json;
async
Complete Example
use McpTransport;
use json;
async
MCP JSON Schema to Thulp Parameters
The thulp-mcp crate automatically converts MCP JSON Schema tool definitions to Thulp's type system:
| MCP JSON Schema Type | Thulp ParameterType |
|---|---|
"string" |
ParameterType::String |
"integer" |
ParameterType::Integer |
"number" |
ParameterType::Number |
"boolean" |
ParameterType::Boolean |
"array" |
ParameterType::Array |
"object" |
ParameterType::Object |
Schema Parsing Example
Given this MCP tool schema:
Thulp will parse it as:
ToolDefinition
Error Handling
The crate provides detailed error types for different failure scenarios:
use ;
async
Connection Lifecycle
use McpTransport;
async
Testing
The crate includes comprehensive tests including edge cases:
# Run all tests
# Run with output
# Run specific test
Implementation Details
Transport Architecture
McpTransport wraps rs-utcp's transport types:
- STDIO: Uses
StdioClientTransportto communicate with child processes - HTTPS: Uses
SseClientTransportfor Server-Sent Events over HTTPS
Tool Provider
The crate implements rs-utcp's ToolProvider trait to enable tool discovery:
Schema Parsing
ToolDefinition::parse_mcp_input_schema handles the conversion from MCP JSON Schema to Thulp parameters. It supports:
- All standard JSON Schema primitive types
- Required vs optional parameters (from
requiredarray) - Nested object schemas (flattened to parameters)
- Missing or malformed schemas (returns empty parameter list)
Compatibility
- MCP Protocol Version: Compatible with MCP protocol as implemented by
rs-utcpv0.3.0 - rs-utcp: Version 0.3.0
- Rust: 1.75+
Feature Flags
ares
Enables integration with the Ares MCP server implementation:
[]
= { = "0.2", = ["ares"] }
This feature:
- Includes
ares-serveras a dependency - Enables Ares-specific utilities and helpers
- Required for testing with Ares-based servers
Examples
See the examples/ directory for more usage examples:
stdio_example.rs: Basic STDIO connectionhttps_example.rs: Remote HTTPS connectiontool_discovery.rs: Tool listing and introspectiontool_execution.rs: Calling tools with validation
You can also run the Thulp examples that demonstrate MCP integration:
# Run the MCP example (requires MCP feature)
See the root examples directory for more comprehensive examples.
Troubleshooting
Server Won't Start
// Check server path
let result = stdio.await;
match result
Tool Not Found
// List available tools first
let tools = transport.list_tools.await?;
for tool in tools
Invalid Parameters
// Check tool definition for required parameters
let tools = transport.list_tools.await?;
let tool = tools.iter.find.unwrap;
for param in &tool.parameters
Contributing
Contributions are welcome! Please ensure:
- Tests pass:
cargo test -p thulp-mcp - Code is formatted:
cargo fmt - No clippy warnings:
cargo clippy -p thulp-mcp - Add tests for new features
- Update documentation
License
Licensed under either of:
- Apache License, Version 2.0
- MIT license
at your option.