Skip to main content

mcp_methods/server/
mod.rs

1//! Reusable building blocks for Rust-native MCP servers.
2//!
3//! The `mcp-server` binary (in the sibling `crates/mcp-server` crate)
4//! is a complete generic MCP server: source navigation, GitHub access
5//! (issues + REST API with drill-down), workspace mode (github
6//! clone-and-track or local directory bind), watch mode, and
7//! manifest-driven Cypher / tool registration. Downstream crates that
8//! want the same framework with domain-specific tools layered on top
9//! depend on `mcp-methods` and call into the public modules below.
10//!
11//! Typical layering pattern:
12//! 1. Construct [`server::ServerOptions`] from a manifest, optionally
13//!    binding source roots, a default repo, or a workspace handle.
14//! 2. `let mut server = server::McpServer::new(options);`
15//! 3. Register your domain-specific tools with
16//!    [`server::McpServer::register_typed_tool`] — typed arg struct
17//!    plus a `Fn(T) -> String` handler — or
18//!    [`server::McpServer::register_typed_tool_fallible`] when the
19//!    handler returns `Result<String, String>` and an `Err` should set
20//!    `isError: true` on the MCP result. (For lower-level control, use
21//!    [`server::McpServer::tool_router_mut`] and rmcp's `ToolRoute`
22//!    directly.)
23//! 4. `server.serve(rmcp::transport::stdio()).await`.
24//!
25//! See `kglite-mcp-server` for a real example: it adds `cypher_query`,
26//! `graph_overview`, and `save_graph` tools that close over an active
27//! graph handle. Python authors running a FastMCP server can compose
28//! tools via the `mcp_methods.fastmcp` helper submodule (Python-side).
29//!
30//! **Note:** the legacy `embedder:` / `tools[].python:` extension hooks
31//! that lived here in 0.3.25 have been removed. They required PyO3 in
32//! the framework's source, which violated the pure-Rust constraint of
33//! this crate. Downstream Python-aware servers (kglite, etc.) implement
34//! their equivalent via a thin pyo3 wrapper in their own cdylib.
35
36pub mod bundled_skills_index;
37pub mod cli;
38pub mod env;
39pub mod manifest;
40pub mod roots;
41pub mod runtime;
42// `server` inside the `server` feature module — the inner module is
43// the rmcp `ServerHandler` impl. Rename would churn every downstream
44// import; allow the inception.
45#[allow(clippy::module_inception)]
46pub mod server;
47pub mod skills;
48pub mod source;
49pub mod watch;
50pub mod workspace;
51
52// Re-export the most commonly used types so downstream crates can
53// `use mcp_methods::server::{Manifest, ServerOptions, McpServer};`
54// without chasing the module hierarchy.
55pub use manifest::{
56    find_sibling_manifest, find_workspace_manifest, load as load_manifest, BuiltinsConfig,
57    EmbedderConfig, Manifest, ManifestError, PythonTool, SkillSource, SkillsSource, TempCleanup,
58    ToolSpec, TrustConfig, WorkspaceConfig, WorkspaceKind,
59};
60pub use runtime::{init_tracing, load_env_for_mode, maybe_watch, resolve_source_roots};
61pub use server::{
62    serve_prompts, McpServer, RepoProvider, ResultCtx, ResultPostprocessHook, ServerOptions,
63};
64pub use skills::{
65    library_bundled_skills, render_skill_template, write_skill_template, AppliesWhen, BundledSkill,
66    GraphPropertyCheck, ParseWarning, PredicateClause, PredicateOutcome, Registry as SkillRegistry,
67    ResolvedRegistry, Skill, SkillActivation, SkillError, SkillFrontmatter,
68    SkillPredicateEvaluator, SkillProvenance,
69};
70pub use source::SourceRootsProvider;
71pub use watch::{watch as watch_dir, ChangeHandler, WatchHandle};
72pub use workspace::{
73    ActivationBuild, ActivationId, ActivationRequest, ActivationSummaryHook,
74    ActivationTransactionHook, PostActivateHook, PostActivateRevsHook, PreparedActivation,
75    RevsRequest, RootOwnership, Workspace,
76};