Skip to main content

Agent and workflow MCP tool adapters for app-owned hosting.

Project description

agent-framework-hosting-mcp

MCP conversion helpers for app-owned Agent Framework hosting.

The package deliberately does not choose a web framework or wrap the MCP SDK server lifecycle. It provides two conversion functions and small adapters:

  • mcp_to_run(...) converts native MCP tool arguments into Agent Framework run arguments.
  • mcp_from_run(...) converts an AgentResponse or Message into native MCP ContentBlock values.
  • AgentMCPTool(...) generates the native Tool definition from an agent and keeps listing, parsing, execution, result conversion, and optional AgentState session persistence aligned.
  • WorkflowMCPTool(...) generates the native Tool definition from a workflow's start-executor input type and converts completed workflow outputs.

Application code keeps ownership of the MCP SDK's Server, handler registration, request context, transport, session-key policy, authentication, authorization, and deployment.

For direct conversion, the argument name is part of the app-owned MCP tool contract. Define it once and use the same value in both the native tool schema and mcp_to_run(...):

agent_input_argument = "task"
chat_option_arguments = {
    "reasoning_effort": {
        "type": "string",
        "enum": ["low", "medium", "high"],
    },
}

tool = Tool(
    name="run_agent",
    inputSchema={
        "type": "object",
        "properties": {
            agent_input_argument: {"type": "string"},
            **chat_option_arguments,
        },
        "required": [agent_input_argument],
    },
)
run = mcp_to_run(
    arguments,
    argument_name=agent_input_argument,
    chat_option_arguments=chat_option_arguments,
)

Only names listed in chat_option_arguments are copied to run["options"]; other MCP arguments remain available in the message's raw representation but are not forwarded to the model client. The native MCP schema remains responsible for validating exposed option types and ranges.

For an agent exposed as one MCP tool, use the adapter so the schema and conversion cannot drift:

agent_tool = AgentMCPTool(
    agent,
    name="run_agent",
    argument_description="The request for the hosted agent.",
    parameters={"audience": {"type": "string"}},
    chat_option_parameters={
        "reasoning_effort": {
            "type": "string",
            "enum": ["low", "medium", "high"],
        }
    },
)

@server.list_tools()
async def list_tools():
    return await agent_tool.list_tools()

@server.call_tool()
async def call_tool(name, arguments):
    return await agent_tool.call_tool(name, arguments)

AgentMCPTool uses the agent's name and description unless overridden. parameters adds app-owned JSON Schema properties that remain available in the raw MCP arguments. chat_option_parameters adds properties and explicitly copies their values into Agent Framework chat options.

For a workflow exposed as one MCP tool, use WorkflowMCPTool:

workflow_tool = WorkflowMCPTool(
    WorkflowState(create_workflow, cache_target=False),
    name="run_workflow",
)

The start executor must declare exactly one input type. Dataclass, Pydantic, and other object-shaped inputs become the MCP tool's top-level arguments. Primitive inputs are wrapped in the configurable argument_name property. The adapter validates MCP arguments against that derived type before calling workflow.run(...).

Workflow instances preserve execution state, so applications that need independent calls should supply a WorkflowState factory with cache_target=False, as above. Checkpoint restoration, human-in-the-loop responses, and continuation identifiers remain application-owned contracts. If a workflow requests external input, the adapter raises instead of returning an empty successful tool result.

Pass an existing AgentState plus session_id_parameter to persist an AgentSession:

state = AgentState(agent)
agent_tool = AgentMCPTool(
    state,
    parameters={"session_id": {"type": "string", "minLength": 1}},
    required_parameters={"session_id"},
    session_id_parameter="session_id",
)

The application must authenticate or authorize that session identifier and serialize concurrent calls for the same session. The adapter only performs the AgentState session-store get/run/set sequence. A configured session parameter is always marked required in the generated MCP schema.

The session identifier is an opaque, application-defined key. Neither MCP nor Agent Framework prescribes its format. AgentMCPTool treats it as the key for one mutable conversation: each call loads that session and stores the updated session under the same key. It does not implement previous_response_id-style branching. Branching requires an app-owned contract with separate source and destination identifiers so the application can authorize both, copy the source session, and store the result under the destination key.

MCP tools/call inputs are JSON objects defined by the app's inputSchema; the protocol does not define image, audio, or resource content blocks for tool arguments. This helper therefore converts one selected string argument and does not impose a non-standard multimodal JSON convention.

For non-image/audio binary output, mcp_from_run(...) uses an app-provided content.additional_properties["uri"] when present and otherwise uses the short fallback af://binary; the payload itself is stored only in the MCP resource's blob field.

mcp_from_run(...) targets CallToolResult.content, whose MCP content union does not include sampling-only ToolUseContent. Agent Framework function_call content is therefore omitted from tool results. MCP sampling callbacks use a separate response contract and may convert function calls to ToolUseContent.

MCP tool calls return one final CallToolResult; they do not stream partial content blocks. Streamable HTTP may carry multiple MCP messages, and apps may send progress notifications while work runs, but neither mechanism turns Agent Framework response updates into incremental tool results. Experimental MCP tasks defer retrieval of the same final result.

run = mcp_to_run(arguments)
result = await agent.run(
    run["messages"],
    options=run["options"],
)
content = mcp_from_run(result)

# Native MCP SDK application code returns `content` from its call_tool handler.

The surrounding MCP application still owns the low-level Server, handler registration, Starlette/FastAPI composition, stdio or streamable HTTP transport, request authentication, session-key trust, concurrency, and deployment.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agent_framework_hosting_mcp-1.0.0a260721.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file agent_framework_hosting_mcp-1.0.0a260721.tar.gz.

File metadata

  • Download URL: agent_framework_hosting_mcp-1.0.0a260721.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for agent_framework_hosting_mcp-1.0.0a260721.tar.gz
Algorithm Hash digest
SHA256 d2b12f3200283ff7ef11476aca782e8b3338798f210ce1275e025dd688dd12f3
MD5 1e59b79c266f444ff149978f9b6b3fad
BLAKE2b-256 a7491b6bc00ab29cd16b6a71f4dc485bbe7415f92a6052025e8dca6ea45d9d23

See more details on using hashes here.

File details

Details for the file agent_framework_hosting_mcp-1.0.0a260721-py3-none-any.whl.

File metadata

  • Download URL: agent_framework_hosting_mcp-1.0.0a260721-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for agent_framework_hosting_mcp-1.0.0a260721-py3-none-any.whl
Algorithm Hash digest
SHA256 f64305f1a9013c0e2151867248e6222a5c34db5659f0405a6f8dd5608235b0d8
MD5 d142ef95a3f98926ec1456a45580718f
BLAKE2b-256 03d0a3df2bf2f0a06cc0328ecdd0f90b75797c20f2e7138e8b21d2d338361579

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page