Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cookbooks/mcp/client.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"outputs": [],
"source": [
"import asyncio\n",
"from appbuilder.modelcontextprotocol.client import MCPClient\n",
"from appbuilder.mcp.client import MCPClient\n",
"\n",
"\n",
"async def main():\n",
Expand Down Expand Up @@ -94,7 +94,7 @@
"outputs": [],
"source": [
"import asyncio\n",
"from appbuilder.modelcontextprotocol.client import MCPClient\n",
"from appbuilder.mcp.client import MCPClient\n",
"\n",
"\n",
"async def main():\n",
Expand Down Expand Up @@ -197,7 +197,7 @@
" AsyncToolCallEventHandler,\n",
")\n",
"\n",
"from appbuilder.modelcontextprotocol.client import MCPClient\n",
"from appbuilder.mcp.client import MCPClient\n",
"\n",
"os.environ[\"APPBUILDER_TOKEN\"] = \"YOUR_APPBUILDER_TOKEN\"\n",
"os.environ[\"APP_ID\"] = \"YOUR_APP_ID\"\n",
Expand Down
2 changes: 1 addition & 1 deletion cookbooks/mcp/server.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"\"\"\"server.py\"\"\"\n",
"\n",
"import os\n",
"from appbuilder.modelcontextprotocol.server import MCPComponentServer\n",
"from appbuilder.mcp.server import MCPComponentServer\n",
"from appbuilder.core.components.v2 import Translation\n",
"from appbuilder.core.components.v2 import Text2Image\n",
"\n",
Expand Down
6 changes: 3 additions & 3 deletions docs/BasisModule/Platform/Application/appbuilder_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ print(msg_2.model_dump_json(indent=4)
import os
import asyncio
import appbuilder
from appbuilder.modelcontextprotocol.client import MCPClient
from appbuilder.mcp.client import MCPClient


async def main():
Expand Down Expand Up @@ -487,7 +487,7 @@ from appbuilder.core.console.appbuilder_client.async_event_handler import (
AsyncAppBuilderEventHandler,
)

from appbuilder.modelcontextprotocol.client import MCPClient
from appbuilder.mcp.client import MCPClient


class MyEventHandler(AsyncAppBuilderEventHandler):
Expand Down Expand Up @@ -578,7 +578,7 @@ from appbuilder.core.console.appbuilder_client.async_event_handler import (
AsyncAppBuilderEventHandler,
)

from appbuilder.modelcontextprotocol.client import MCPClient
from appbuilder.mcp.client import MCPClient


@appbuilder.manifest(
Expand Down
1 change: 1 addition & 0 deletions python/core/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class Plan(BaseModel, extra='allow'):
# deprecated parameters, delete when dte agent update
detail: str = Field(default="", description="计划详情")
steps: list[PlanStep] = Field(default=[], description="步骤列表")
# this is check pr


class FunctionCall(BaseModel, extra='allow'):
Expand Down
87 changes: 87 additions & 0 deletions python/mcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# MCP Component Server

The MCP Component Server is a FastMCP server based implementation that converts AppBuilder Components into FastMCP tools, enabling seamless integration of Baidu cloud AI services into MCP-compatible environments.

## Overview

The `MCPComponentServer` class provides a bridge between AppBuilder Components and FastMCP tools, allowing you to:
- Convert AppBuilder Components into MCP-compatible tools
- Handle various content types (text, images, audio, references)
- Manage visibility scopes for different audiences
- Support streaming responses through generators

## Features

- Automatic conversion of AppBuilder Components to MCP tools
- Support for multiple content types:
- Text content
- Image content
- Audio content
- Reference content
- Configurable host and port settings
- Built-in error handling and logging
- Support for custom tool registration
- Automatic MIME type detection for media content

## Usage

### Basic Setup

```python
from appbuilder import GeneralOCR, TextGeneration
from mcp.server import MCPComponentServer

# Create server instance
server = MCPComponentServer("AI Service", host="localhost", port=8000)

# Add AppBuilder components
ocr = GeneralOCR()
server.add_component(ocr)

text_gen = TextGeneration()
server.add_component(text_gen)

# Run the server
server.run()
```

### Adding Custom Tools

```python
@server.tool()
def custom_function(param1: str, param2: int) -> str:
"""Custom tool description"""
return f"Processed: {param1} {param2}"
```

### Adding Resources

```python
@server.resource()
def get_resource():
"""Resource description"""
return {"data": "resource content"}
```

## Content Type Handling

The server automatically handles various content types:

1. **Text Content**: Converts text outputs to MCP TextContent
2. **Image Content**: Handles both base64 and URL-based images
3. **Audio Content**: Processes audio files with automatic MIME type detection
4. **Reference Content**: Manages document references and citations


## Configuration

The server can be configured with various parameters:

```python
server = MCPComponentServer(
name="Service Name",
host="localhost", # Default: "localhost"
port=8000, # Default: 8000
**kwargs # Additional FastMCP arguments
)
```
File renamed without changes.
27 changes: 27 additions & 0 deletions python/mcp/ai_search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Baidu AI Search

Baidu AI Search component combines Baidu's search capabilities with large language model technology to provide intelligent responses with real-time web information references, supporting various industry application scenarios. It offers rich standardized capabilities such as:

- Custom persona settings
- Model selection
- Query rewriting (including time-sensitive and multi-turn approaches to enhance search results)
- Search scope configuration (choice of modalities, site ranges and publication dates)
- Customizable number of reference links

## Quick Start

1. Get your AppBuilder API Key from the console
2. Format your authorization token as: `Bearer+<AppBuilder API Key>` (keep the "+" in between)
3. Config with

```json
{
"mcpServers": {
"baidu_ai_search": {
"url": "http://appbuilder.baidu.com/v2/ai_search/mcp/sse?api_key=Bearer+bce-v3/ALTAK..."
}
}
}
```

For more details, please refer to [百度AI搜索](https://cloud.baidu.com/doc/AppBuilder/s/zm8pn5cju)
File renamed without changes.
File renamed without changes.
71 changes: 0 additions & 71 deletions python/modelcontextprotocol/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion python/tests/test_appbuilder_client_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async def process():
await appbuilder_client.http_client.session.close()
await mcp_client.cleanup()

from appbuilder.modelcontextprotocol.client import MCPClient
from appbuilder.mcp.client import MCPClient
subprocess.check_call([sys.executable, "-m", "pip", "install", "mcp"])
loop = asyncio.get_event_loop()
loop.run_until_complete(process())
Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_appbuilder_client_mcp_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async def handler():
[sys.executable, "-m", "pip", "uninstall", "-y", "chainlit"]
)
subprocess.check_call([sys.executable, "-m", "pip", "install", "mcp"])
from appbuilder.modelcontextprotocol.client import MCPClient
from appbuilder.mcp.client import MCPClient
asyncio.run(handler())


Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_appbuilder_client_mcp_official.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async def handler():
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "mcp"]
)
from appbuilder.modelcontextprotocol.client import MCPClient
from appbuilder.mcp.client import MCPClient
asyncio.run(handler())


Expand Down
Loading