The MCPApp provides seamless integration with Model Context Protocol (MCP) servers,
allowing Meta Agents Research Environments to connect to and utilize tools from any MCP-compatible server.
This enables modular tool organization and dynamic tool discovery.
The Model Context Protocol (MCP) is a standardized way for applications to provide
tools and resources to AI systems.
The MCPApp acts as a bridge between Meta Agents Research Environments and MCP servers, automatically discovering
available tools and exposing them as Meta Agents Research Environments app tools.
Key features:
Universal Compatibility: Works with any MCP-compatible server
Dynamic Discovery: Automatically discovers tools, resources, and prompts
Flexible Connection: Supports both stdio and Server-Sent Events (SSE) connections
Tool Filtering: Filter tools by read-only status or exclude specific tools
Rich Annotations: Preserves MCP tool annotations for better tool understanding
Working with external services that provide MCP interfaces
Rapid prototyping of new functionality
Leveraging community-developed tools
No need for scenario reproducibility
Choose Meta Agents Research Environments Apps When:
Modeling complete applications or systems
Need complex state management
Require inter-app communication
Building simulation-specific functionality
Need fine-grained control over tool behavior and presentation
Need to reproduce scenarios across multiple runs
Hybrid Approach:
The most powerful approach often combines both:
# Custom Meta Agents Research Environments app for core functionalityemail_app=EmailClientApp()# MCP integration for external servicescode_exec=MCPApp(name="CodeExecution",server_command="code-mcp-server")wiki_mcp=MCPApp(name="Wikipedia",server_command="wikipedia-mcp-server")# All work together in the same simulationscenario=Scenario(apps=[email_app,code_exec,wiki_mcp])
This hybrid approach provides the best of both worlds: the rich application modeling of Meta Agents Research Environments Apps combined with the extensive ecosystem and standardization of MCP tools.
For local MCP servers that communicate via standard input/output:
fromare.simulation.apps.mcp.mcp_appimportMCPApp# Connect to a local Python MCP servermath_app=MCPApp(name="MathTools",server_command="python",server_args=["path/to/math_server.py"],server_env={"PYTHONPATH":"/custom/path"}# Optional environment variables)
The MCPApp supports authentication for remote MCP servers through HTTP headers.
Currently, long-lived tokens are supported for authentication. OAuth2 support
is not available at this time.
For servers that require authentication via long-lived tokens (such as Home Assistant),
you can provide authentication headers when creating the MCPApp:
# Example: Home Assistant MCP server with long-lived tokenha_app=MCPApp(name="Home Assistant",server_url="http://192.168.0.189:8123/mcp_server/sse",sse_headers={"Authorization":"Bearer YOURLONGLIVEDTOKENS",})
The sse_headers parameter accepts a dictionary of HTTP headers that will be
sent with each request to the MCP server. This allows for flexible authentication
methods depending on your server’s requirements.
Note
OAuth2 authentication is not currently supported. For now, use long-lived
tokens or API keys provided by your MCP server.
app=MCPApp(name="MyMCPApp",# App name in Meta Agents Research Environmentsserver_command="python",# Command to run the serverserver_args=["server.py"],# Arguments for the servertimeout=10.0# Timeout for operations)
app=MCPApp(name="FilteredApp",server_command="python",server_args=["server.py"],server_env={"DEBUG":"1"},# Environment variablesexclude_tools=["dangerous_tool"],# Tools to excludeonly_read_only=True,# Only include read-only toolsdescription_modifier=custom_desc# Function to modify descriptions)
The MCPApp provides powerful filtering capabilities. Excluding some tools or keep only_read_only,
can help use MCPApps in a safer and reproducible way:
Filter tools to only include those marked as read-only:
# Only expose read-only tools (safe for exploration)readonly_app=MCPApp(name="SafeTools",server_command="python",server_args=["server.py"],only_read_only=True)
defenhance_description(tool_name:str,original_desc:str)->str:iftool_name=="divide":returnf"{original_desc} (Note: Does not work with negative numbers)"returnoriginal_descapp=MCPApp(name="EnhancedTools",server_command="python",server_args=["server.py"],description_modifier=enhance_description)
A Meta Agents Research Environments app that connects to an MCP server and exposes its tools.
This app allows Meta Agents Research Environments to interact with any MCP-compatible server, making
the server’s tools available as Meta Agents Research Environments app tools.
Initialize the MCP app and connect to the server immediately.
Parameters:
name (Optional[str]) – Optional name for the app. Defaults to “MCPApp”.
server_command (Optional[str]) – The command to run the MCP server for stdio connection.
server_args (Optional[list[str]]) – Arguments to pass to the server command.
server_env (Optional[dict[str, str]]) – Environment variables to set for the server.
server_url (Optional[str]) – URL for SSE server connection. If provided, stdio parameters are ignored.
sse_headers (Optional[dict[str, Any]]) – If using an SSE server, you can pass connection headers (httpx headers).
description_modifier (Optional[Callable[[str, str | None], str | None]]) – A function that modifies the description returned by the mcp server.
Signature is change_description(tool_name: str, server_description: str | None) -> str | None
exclude_tools (Optional[list[str]]) – List of tool names to exclude from the app.
only_read_only (bool) – If True, only include tools marked as read-only.
timeout (float) – Timeout in seconds for async operations. Defaults to 10.0.
A Meta Agents Research Environments app that connects to an MCP server and exposes its tools.
This app allows Meta Agents Research Environments to interact with any MCP-compatible server, making
the server’s tools available as Meta Agents Research Environments app tools.
Initialize the MCP app and connect to the server immediately.
Parameters:
name (Optional[str]) – Optional name for the app. Defaults to “MCPApp”.
server_command (Optional[str]) – The command to run the MCP server for stdio connection.
server_args (Optional[list[str]]) – Arguments to pass to the server command.
server_env (Optional[dict[str, str]]) – Environment variables to set for the server.
server_url (Optional[str]) – URL for SSE server connection. If provided, stdio parameters are ignored.
sse_headers (Optional[dict[str, Any]]) – If using an SSE server, you can pass connection headers (httpx headers).
description_modifier (Optional[Callable[[str, str | None], str | None]]) – A function that modifies the description returned by the mcp server.
Signature is change_description(tool_name: str, server_description: str | None) -> str | None
exclude_tools (Optional[list[str]]) – List of tool names to exclude from the app.
only_read_only (bool) – If True, only include tools marked as read-only.
timeout (float) – Timeout in seconds for async operations. Defaults to 10.0.
Initialize the MCP app and connect to the server immediately.
Parameters:
name (Optional[str]) – Optional name for the app. Defaults to “MCPApp”.
server_command (Optional[str]) – The command to run the MCP server for stdio connection.
server_args (Optional[list[str]]) – Arguments to pass to the server command.
server_env (Optional[dict[str, str]]) – Environment variables to set for the server.
server_url (Optional[str]) – URL for SSE server connection. If provided, stdio parameters are ignored.
sse_headers (Optional[dict[str, Any]]) – If using an SSE server, you can pass connection headers (httpx headers).
description_modifier (Optional[Callable[[str, str | None], str | None]]) – A function that modifies the description returned by the mcp server.
Signature is change_description(tool_name: str, server_description: str | None) -> str | None
exclude_tools (Optional[list[str]]) – List of tool names to exclude from the app.
only_read_only (bool) – If True, only include tools marked as read-only.
timeout (float) – Timeout in seconds for async operations. Defaults to 10.0.
Convert the tool to OpenAI function calling format.
Example:
{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}
readOnlyHint: Whether the tool modifies its environment
destructiveHint: Whether modifications are destructive or additive
idempotentHint: Whether repeated calls have the same effect
openWorldHint: Whether the tool interacts with external entities
title: Human-readable title for the tool
The MCPApp provides a powerful and flexible way to extend Meta Agents Research Environments with external tools while maintaining safety and control through comprehensive filtering and annotation support.