subgraph
Retrieve a list of available subgraph names or query the nodes within a named subgraph for code analysis.
Instructions
Return available subgraph names or the nodes in a named subgraph.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | ||
| session_id | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/trailmark_mcp/mcp_app.py:110-113 (handler)MCP tool handler for 'subgraph' — delegates to TrailmarkRuntime.subgraph(). This is the entry point when the MCP server calls the 'subgraph' tool.
@mcp.tool() def subgraph(name: str | None = None, session_id: str | None = None) -> list[str] | list[dict[str, Any]]: """Return available subgraph names or the nodes in a named subgraph.""" return app_runtime.subgraph(name=name, session_id=session_id) - TrailmarkRuntime.subgraph() — the core runtime logic. If name is None, returns available subgraph names via engine.subgraph_names(); otherwise returns the nodes in the named subgraph via engine.subgraph(name).
def subgraph( self, name: str | None = None, session_id: str | None = None, ) -> list[str] | list[dict[str, Any]]: engine = self._require_scanned_handle(session_id).engine if name is None: return engine.subgraph_names() return engine.subgraph(name) - ToolSpec definition for 'subgraph' — declares the tool name, category ('context'), description, and parameters (name: string|null with default None, session_id: string|null with default None).
ToolSpec( name="subgraph", category="context", description="Return available subgraph names or the nodes contained in a named subgraph.", parameters={"name": _param("string|null", default=None), "session_id": SESSION_ID_PARAM}, ), - tests/test_stdio_server.py:50-50 (registration)Test assertion confirming that 'subgraph' is listed among the available tool names by the MCP server.
assert "subgraph" in tool_names - Serialization of subgraphs to JSON when saving snapshots — uses engine.subgraph(name) to resolve each subgraph name to sorted node IDs.
"subgraphs": {name: sorted(ids) for name, ids in graph.subgraphs.items()},