-
Notifications
You must be signed in to change notification settings - Fork 0
Components
Sai Sravan Kathi edited this page Jun 6, 2026
·
1 revision
This document provides a breakdown of each Python file in the MCP Explorer codebase, explaining its significance and architectural role.
The central configuration hub of the application. It manages dynamic configuration reloading based on environments.
-
Significance: Loads variables from
.env,.env.test, or.env.proddepending on the value of theMCP_ENVenvironment variable (falling back to.envif undefined). -
Key Objects:
CONFIG(dictionary housingOLLAMA_URL,MONGODB_URI,LOG_LEVEL, and pathways to tools/MCP configuration files).
The brain of the system.
-
Significance: Defines the custom
Agentclass wrapper. It instantiatesChatOllamautilizing thegemma4:e4bmodel and binds it to a list of dynamically resolved tools using LangGraph'screate_react_agent. -
Key Methods:
-
ainvoke(prompt, thread_id, callbacks): Starts the agent as an asynchronous generator utilizingastream_eventsto yield granular execution events (model responses, token outputs, tool inputs/outputs) back to the caller.
-
The diagnostic tracing console callback.
-
Significance: Extends LangChain's
BaseCallbackHandlerto format and print colored, structured execution logs directly to the system CLI. -
Key Methods:
-
on_chain_start()/on_chain_end(): Logs execution boundaries of sub-graphs. -
on_tool_start()/on_tool_end(): Traces the exact input and outputs of standard/MCP tool execution.
-
Connects the agent to external tool suites using the Model Context Protocol.
-
Significance: Parses
mcpConfig.json, spawns each configured MCP server (e.g. SQLite, local scripts) as an independent OS process, establishes stdin/stdout channels, and maps their exposed JSON-RPC tools into LangChain compatible tool interfaces.
The dynamic initializer for standard LangChain integrations.
- Significance: Resolves issues with third-party tools that require code-level adjustments (such as configuring User-Agent credentials for Wikipedia or overriding Arxiv query parameters).
-
Key Methods:
-
load_standard_tools(config_path): ReadstoolsConfig.json, compiles and executes thetool_initsPython code snippets dynamically viaexec(), then registers these standard tools into the agent scope.
-
The frontend coordinator.
- Significance: Orchestrates Chainlit's user lifecycle events.
-
Workflow:
-
@cl.on_chat_start: Initializes tools, establishes MCP servers context, and instantiates theAgentobject. -
@cl.on_message: Triggersagent.ainvoke, streaming response tokens in real-time to the user's browser. In thefinallyblock, it parses the underlyinglangfuse_handler.last_trace_idand manually updates the trace payload in Langfuse (assigning trace input and the name"MCP Explorer Agent").
-