The MCP (Model Context Protocol) Tool enables structured context provision for agents. MCP allows agents to receive rich, structured context about their environment, available tools, and action requirements, enabling better decision-making and action execution.
The MCP Tool follows mindX doctrine:
data/mcp/ with contexts and tool definitionsfrom tools.mcp_tool import MCPTool
from agents.memory_agent import MemoryAgent
memory_agent = MemoryAgent()
mcp_tool = MCPTool(memory_agent=memory_agent)
result = await mcp_tool.execute(
operation="create_context",
context_type="action_context",
agent_id="my_agent",
action_id="analyze_code",
context_data={
"code": "...",
"language": "python",
"requirements": ["syntax_check", "type_check"]
},
schema={
"type": "object",
"properties": {
"code": {"type": "string"},
"language": {"type": "string"},
"requirements": {"type": "array"}
}
}
)
context_id = result["context_id"]
result = await mcp_tool.execute(
operation="register_tool",
tool_id="code_analyzer",
name="Code Analyzer",
description="Analyzes code for issues and improvements",
parameters={
"type": "object",
"properties": {
"code": {"type": "string", "description": "Code to analyze"},
"language": {"type": "string", "description": "Programming language"}
},
"required": ["code", "language"]
},
returns={
"type": "object",
"properties": {
"issues": {"type": "array"},
"suggestions": {"type": "array"}
}
},
examples=[
{
"input": {"code": "def hello():", "language": "python"},
"output": {"issues": [], "suggestions": ["Add docstring"]}
}
]
)
result = await mcp_tool.execute(
operation="get_tool_context",
agent_id="my_agent",
tool_id="code_analyzer"
)
context = result["context"]
Contains tool definition, parameters, examples, etc.
result = await mcp_tool.execute(
operation="get_action_context",
agent_id="my_agent",
action_id="analyze_code"
)
context = result["context"]
Contains action-specific context data
# List all contexts
result = await mcp_tool.execute(operation="list_contexts")
Filter by agent
result = await mcp_tool.execute(
operation="list_contexts",
agent_id="my_agent"
)
Filter by type
result = await mcp_tool.execute(
operation="list_contexts",
context_type="tool_definition"
)
create_context: Create a new MCP contextget_context: Get context by IDupdate_context: Update an existing contextdelete_context: Delete a contextlist_contexts: List all contexts (with filters)register_tool: Register a tool definitionget_tool_definition: Get tool definitionlist_tools: List all tool definitionsget_action_context: Get context for an actionget_tool_context: Get context for a tooltool_definition: Tool definitions with schemasaction_context: Context for specific actionsenvironment_state: Current environment statecapability_description: Capability descriptionsexecution_parameters: Execution parametersresult_schema: Result schemasThe MCP Tool integrates with:
data/mcp/
├── contexts_registry.json # Contexts registry
├── tool_definitions_registry.json # Tool definitions registry
├── contexts/ # Individual contexts
│ └── {context_id}.json
└── tool_definitions/ # Individual tool definitions
└── {tool_id}.json