Skip to main content

sim_lib_mcp/
manifest.rs

1use sim_kernel::{AbiVersion, Lib, LibManifest, LibTarget, Linker, Result, Symbol, Version};
2
3use crate::{MCP_LIB_ID, McpFunction, ops::McpFunctionKind};
4
5/// Loadable library that registers the MCP method functions in a runtime.
6pub struct McpLib;
7
8impl Lib for McpLib {
9    fn manifest(&self) -> LibManifest {
10        LibManifest {
11            id: manifest_name(),
12            version: Version(env!("CARGO_PKG_VERSION").to_owned()),
13            abi: AbiVersion { major: 0, minor: 1 },
14            target: LibTarget::HostRegistered,
15            requires: Vec::new(),
16            capabilities: Vec::new(),
17            exports: crate::ops::mcp_exports(),
18        }
19    }
20
21    fn load(&self, cx: &mut sim_kernel::LoadCx, linker: &mut Linker<'_>) -> Result<()> {
22        for kind in [
23            McpFunctionKind::Handle,
24            McpFunctionKind::Initialize,
25            McpFunctionKind::Tools,
26            McpFunctionKind::Call,
27            McpFunctionKind::Resources,
28            McpFunctionKind::Read,
29            McpFunctionKind::Prompts,
30            McpFunctionKind::GetPrompt,
31            #[cfg(feature = "sampling")]
32            McpFunctionKind::SamplingRunner,
33            McpFunctionKind::Health,
34        ] {
35            let function = McpFunction::value(kind);
36            linker.function_value(function.symbol(), cx.factory().opaque(function)?)?;
37        }
38        Ok(())
39    }
40}
41
42/// Returns the symbol under which [`McpLib`] is registered.
43pub fn manifest_name() -> Symbol {
44    Symbol::new(MCP_LIB_ID)
45}