mcp_tool.md · 5.4 KB

MCP Tool

Summary

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.

Technical Explanation

The MCP Tool follows mindX doctrine:

Architecture

Features

Usage

Creating a Context

from 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"]

Registering a Tool

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"]}
        }
    ]
)

Getting Tool Context

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.

Getting Action Context

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

Listing Contexts

# 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" )

Operations

Context Types

Integration

The MCP Tool integrates with:

File Structure

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

Use Cases

  1. Action Planning: Provide context for agent action planning
  2. Tool Discovery: Help agents understand available tools
  3. Parameter Validation: Validate action parameters using schemas
  4. Result Interpretation: Understand expected result formats
  5. Environment Awareness: Provide environment state to agents
  6. Capability Matching: Match agent capabilities with requirements

All DocumentsDocument IndexThe Book of mindXImprovement JournalAPI Reference