MCP server introspection using the official rmcp SDK.
[dependencies]
mcp-execution-introspector = "0.6"Or with cargo-add:
cargo add mcp-execution-introspectorImportant
Requires Rust 1.89 or later.
use mcp_execution_introspector::Introspector;
use mcp_execution_core::{ServerId, ServerConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut introspector = Introspector::new();
let server_id = ServerId::new("github");
let config = ServerConfig::builder()
.command("npx".to_string())
.arg("-y".to_string())
.arg("@modelcontextprotocol/server-github".to_string())
.env("GITHUB_TOKEN".to_string(), "ghp_xxx".to_string())
.build();
let info = introspector.discover_server(server_id, &config).await?;
println!("Server: {} v{}", info.name, info.version);
println!("Tools found: {}", info.tools.len());
for tool in &info.tools {
println!(" - {}: {}", tool.name, tool.description);
}
Ok(())
}let info = introspector.discover_server(server_id, &config).await?;
for tool in &info.tools {
println!("Tool: {}", tool.name);
println!("Schema: {}", serde_json::to_string_pretty(&tool.input_schema)?);
}Tip
Tool schemas are JSON Schema objects that can be used for TypeScript type generation.
// npx-based servers
let config = ServerConfig::builder()
.command("npx".to_string())
.arg("-y".to_string())
.arg("@modelcontextprotocol/server-github".to_string())
.build();
// Docker-based servers
let config = ServerConfig::builder()
.command("docker".to_string())
.arg("run".to_string())
.arg("-i".to_string())
.arg("--rm".to_string())
.arg("ghcr.io/org/mcp-execution-server".to_string())
.build();Note
Currently supports stdio transport, which is the most common for MCP servers.
- Official SDK: Uses rmcp for MCP communication
- Tool Discovery: Extract all tools from any MCP server
- Schema Extraction: Get JSON schemas for tool parameters
- Capability Detection: Discover tools, resources, prompts support
- Caching: Store discovered server information
- Security: Command validation prevents injection attacks
| Type | Description |
|---|---|
Introspector |
Main introspection service with caching |
ServerInfo |
Discovered server metadata and tools |
ToolInfo |
Tool name, description, and JSON schema |
ServerCapabilities |
Flags for tools, resources, prompts support |
- Validate Config — Check server configuration for security issues
- Spawn Process — Start MCP server via stdio transport
- Connect — Establish rmcp client connection
- Query — Use
ServiceExt::list_all_tools()to get tools - Extract — Parse tool definitions and schemas
- Cache — Store information for later retrieval
This crate is part of the mcp-execution workspace:
mcp-execution-core- Foundation types (ServerId,ServerConfig)mcp-execution-codegen- Uses introspection results for code generationrmcp- Official Rust MCP SDK
Minimum Supported Rust Version: 1.89
MSRV increases are considered minor version bumps.
Licensed under either of Apache License 2.0 or MIT license at your option.