Skip to main content
The Serve module enables developers to expose components built with the BeeAI Framework through a server to external clients. Out of the box, we provide implementations for prominent protocols such as A2A and MCP, allowing you to quickly serve existing functionalities. You can also create your own custom adapter if needed.
Location within the framework: beeai_framework/serve.

Supported Providers

The following table lists the currently supported providers:
NameInstallation
A2Apip install beeai-framework[a2a]
Agent Stackpip install beeai-framework[agentstack]
MCPpip install beeai-framework[mcp]
IBM watsonx Orchestratepip install beeai-framework
OpenAI Chat Completion APIpip install beeai-framework
OpenAI Responses APIpip install beeai-framework
Click on the provider name to see a dedicate page how to use it.

How it works

Once you initiate the appropriate server class (eg: AgentStackServer, OpenAIServer, …) you can do the following.
  • Register a new member (register method).
  • Deregister an existing member (deregister method).
  • List existing members (members property).
  • Run the server (serve method / aserve method).
You can typically register one of the followings: If the given instance is not supported, the register method will raise an exception. Nevertheless, you can easily register a custom factory to make it supported.

Register a custom factory

If the given server doesn’t support (or you just want to override the conversion is done) you can register a custom factory function which takes the instance of a given type and converts it into an instance that the server knows how to work with. The following example showcases how we can add a support for PromptTemplate class (which exists in BeeAI Framework) so that it gets exposed as a Prompt in the MCP Server.
Python
from typing import Any

from mcp.server.fastmcp.prompts.base import Prompt as MCPPrompt
from mcp.server.fastmcp.prompts.base import PromptArgument
from pydantic import BaseModel

from beeai_framework.adapters.mcp import MCPServer, MCPServerConfig
from beeai_framework.template import PromptTemplate


def add_prompt_template_factory() -> None:
    def factory(instance: PromptTemplate[Any]) -> MCPPrompt:
        return MCPPrompt(
            name=instance.name,
            title=instance.name,
            description=instance.description,
            arguments=[
                PromptArgument(
                    name=k, description=v.description, required=v.default is None and v.default_factory is None
                )
                for k, v in instance.input_schema.model_fields.items()
            ],
            fn=lambda **kwargs: instance.render(kwargs),
        )

    MCPServer.register_factory(PromptTemplate, factory, override=True)


def run_server() -> None:
    class GreetingTemplateModel(BaseModel):
        name: str

    my_template = PromptTemplate(
        template="Hello {name}",
        schema=GreetingTemplateModel,
    )

    server = MCPServer(config=MCPServerConfig(transport="streamable-http"))
    server.register(my_template)
    server.serve()


if __name__ == "__main__":
    add_prompt_template_factory()
    run_server()

Examples