Skip to content
Closed
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
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.
26 changes: 26 additions & 0 deletions python/mcp/ai_search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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

{
"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: https://cloud.baidu.com/doc/AppBuilder/s/zm8pn5cju
5 changes: 5 additions & 0 deletions python/mcp/ai_search/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

from .ai_search_server import search

__all__ = ["search"]

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
Baidu AI Search MCP Server stdio server file.
Baidu AI Search MCP Server.
We also support access via SSE protocol. The access address is:
http://appbuilder.baidu.com/v2/ai_search/mcp/sse?api_key=<your api_key>
You can refer to this webpage https://cloud.baidu.com/doc/AppBuilder/s/klv2eywua to obtain the api_key, in the format of "Bearer+bce…".
"""
import os

import json
from mcp.server import FastMCP
from appbuilder.core.components.rag_with_baidu_search_pro import RagWithBaiduSearchPro
Expand All @@ -22,7 +22,7 @@


@server.tool()
def AIsearch(
def search(
query,
stream=False,
instruction=None,
Expand Down Expand Up @@ -50,10 +50,10 @@ def AIsearch(
AppBuilderServerException: 如果输入信息或指令过长,将抛出此异常。
"""
message = SimpleNamespace(role="user", content="{}".format(query))
search_instance = RagWithBaiduSearchPro(
component = RagWithBaiduSearchPro(
model=init_args["model"]
)
response = search_instance.run(
response = component.run(
message=message,
stream=stream,
instruction=instruction,
Expand Down
File renamed without changes.
File renamed without changes.
71 changes: 0 additions & 71 deletions python/modelcontextprotocol/README.md

This file was deleted.