diff --git a/cookbooks/mcp/client.ipynb b/cookbooks/mcp/client.ipynb index 172906eb3..350537cfe 100644 --- a/cookbooks/mcp/client.ipynb +++ b/cookbooks/mcp/client.ipynb @@ -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", @@ -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", @@ -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", diff --git a/cookbooks/mcp/server.ipynb b/cookbooks/mcp/server.ipynb index d03af8e12..f90d72f3d 100644 --- a/cookbooks/mcp/server.ipynb +++ b/cookbooks/mcp/server.ipynb @@ -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", diff --git a/docs/BasisModule/Platform/Application/appbuilder_client.md b/docs/BasisModule/Platform/Application/appbuilder_client.md index f4a5dfb56..c85c0423f 100644 --- a/docs/BasisModule/Platform/Application/appbuilder_client.md +++ b/docs/BasisModule/Platform/Application/appbuilder_client.md @@ -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(): @@ -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): @@ -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( diff --git a/python/core/component.py b/python/core/component.py index 887b6d589..d419b8d11 100644 --- a/python/core/component.py +++ b/python/core/component.py @@ -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'): diff --git a/python/mcp/README.md b/python/mcp/README.md new file mode 100644 index 000000000..67f7da309 --- /dev/null +++ b/python/mcp/README.md @@ -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 +) +``` diff --git a/python/modelcontextprotocol/__init__.py b/python/mcp/__init__.py similarity index 100% rename from python/modelcontextprotocol/__init__.py rename to python/mcp/__init__.py diff --git a/python/mcp/ai_search/README.md b/python/mcp/ai_search/README.md new file mode 100644 index 000000000..86f463189 --- /dev/null +++ b/python/mcp/ai_search/README.md @@ -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+` (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) \ No newline at end of file diff --git a/python/modelcontextprotocol/ai_search_server.py b/python/mcp/ai_search/ai_search_server.py similarity index 100% rename from python/modelcontextprotocol/ai_search_server.py rename to python/mcp/ai_search/ai_search_server.py diff --git a/python/modelcontextprotocol/client.py b/python/mcp/client.py similarity index 100% rename from python/modelcontextprotocol/client.py rename to python/mcp/client.py diff --git a/python/modelcontextprotocol/server.py b/python/mcp/server.py similarity index 100% rename from python/modelcontextprotocol/server.py rename to python/mcp/server.py diff --git a/python/modelcontextprotocol/README.md b/python/modelcontextprotocol/README.md deleted file mode 100644 index 34341ae04..000000000 --- a/python/modelcontextprotocol/README.md +++ /dev/null @@ -1,71 +0,0 @@ -### Baidu AISearch MCP Server - -An MCP server implementation that integrates the Baidu AI search API, providing web search capabilities and summary of LLM. The Baidu AI Search Component combines Baidu Search capabilities with large model technology, providing intelligent response functions with real-time information from the entire network, and supporting a variety of industry scenarios. - -### Features - -* **Integration of Search and Large Model Technology**: The component seamlessly merges Baidu’s powerful search engine with advanced large model technology, enabling intelligent and contextually aware responses. -* **Real-time Information Access**: It provides users with up-to-date information from across the internet, ensuring relevant and timely replies. -* **Versatile Applications**: The component caters to a wide range of industries and scenarios, offering flexible solutions for various use cases. -* **Standardized and Customizable Features**: Users can customize personas, choose from different models, rewrite questions for enhanced search results, configure search scopes, and specify the number of reference links, among other options. -* **Enhanced Performance and Availability**: The API delivers high performance and reliability, ensuring smooth and uninterrupted service. -* **Comprehensive Content Safety**: With rigorous content safety reviews, the component ensures all responses and information remain compliant and within acceptable standards. - -### Tools - -* AIsearch - * Execute web searches with pagination and filtering - * Inputs: - - query (str): The search request. - - stream (bool, optional): Whether to receive response data in streaming format. Defaults to False. - - instruction (Instruction, optional): Instruction information object. Defaults to None. - - temperature (float, optional): Temperature parameter to control the randomness of generated text. Defaults to 1e-10. - - top_p (float, optional): Cumulative probability threshold for controlling the diversity of generated text. Defaults to 1e-10. - - search_top_k (int, optional): The number of search candidate results. Defaults to 4. - - hide_corner_markers (bool, optional): Whether to hide the boundary markers in the response. Defaults to True. - -### Configuration - -#### Getting an API Key - -You can refer to this webpage https://cloud.baidu.com/doc/AppBuilder/s/klv2eywua to obtain the api_key - -#### Usage with Claude Desktop - -Add this to your `claude_desktop_config.json`: - -##### python -```json -{ - "mcpServers": { - "AB Component Server": { - "command": "/path/to/your/python3.12", - "args": [ - "/path/to/your/ai_search_server.py" - ], - "envs": { - "APPBUILDER_TOKEN": "{AppBuilder API Key}" - } - } - } -} -``` - -#### Usage with Cursor - -* the format of api_key is “Bearer+”, note that “+” in the middle should be retained, example: Bearer+bce-v3/ALTAK-xuZRMCVTC9###### - -```json - -{ - "mcpServers": { - "AISearch": { - "url": "http://appbuilder.baidu.com/v2/ai_search/mcp/sse?api_key={Bearer+}" - } - } -} -``` - -### License - -Copyright (c) 2024 Baidu, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/python/tests/test_appbuilder_client_mcp.py b/python/tests/test_appbuilder_client_mcp.py index 86e59219e..da680edee 100644 --- a/python/tests/test_appbuilder_client_mcp.py +++ b/python/tests/test_appbuilder_client_mcp.py @@ -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()) diff --git a/python/tests/test_appbuilder_client_mcp_component.py b/python/tests/test_appbuilder_client_mcp_component.py index 294fd6cc6..efb35a370 100644 --- a/python/tests/test_appbuilder_client_mcp_component.py +++ b/python/tests/test_appbuilder_client_mcp_component.py @@ -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()) diff --git a/python/tests/test_appbuilder_client_mcp_official.py b/python/tests/test_appbuilder_client_mcp_official.py index 5cce9a525..d2584d30d 100644 --- a/python/tests/test_appbuilder_client_mcp_official.py +++ b/python/tests/test_appbuilder_client_mcp_official.py @@ -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())