Skip to content

Commit 48d2265

Browse files
committed
update readme
1 parent 3f2edfd commit 48d2265

2 files changed

Lines changed: 305 additions & 48 deletions

File tree

Lines changed: 99 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,74 @@
1-
# Vanilla Agent with Custom Features
1+
# Vanilla Agent with MCP Tools
22

3-
This is a simple example agent that demonstrates how to detect and report which custom features are enabled or disabled in the OpenBB Workspace UI.
3+
This agent demonstrates how to integrate and use Model Context Protocol (MCP) tools within an OpenBB agent, enabling dynamic tool execution for enhanced functionality.
44

55
## What it does
66

77
This agent:
8-
- Greets users with a friendly hello message
9-
- Reports the status of custom features (Deep Research and Web Search)
10-
- Shows whether each feature is enabled (✅) or disabled (❌) based on the UI settings
8+
- Detects and lists available MCP tools from connected MCP servers
9+
- Executes MCP tools with proper parameter handling
10+
- Formats responses clearly separating MCP tool output from AI analysis
11+
- Supports real-time tool execution through the OpenBB frontend
1112

12-
## Features
13+
## Key Features
1314

14-
The agent defines two custom features in its configuration:
15-
- **Deep Research**: Allows the agent to perform deep research (default: disabled)
16-
- **Web Search**: Allows the agent to search the web (default: enabled)
15+
### MCP Tool Integration
16+
- **Automatic Tool Detection**: Discovers MCP tools from connected servers
17+
- **Parameter Schema Support**: Validates and passes parameters based on tool schemas
18+
- **Server Management**: Handles multiple MCP servers with proper server ID mapping
19+
- **Error Handling**: Graceful fallbacks when tools are unavailable or fail
1720

18-
Users can toggle these features on/off in the OpenBB Workspace UI, and the agent will detect and report the current status.
21+
### Response Formatting
22+
All responses with MCP tool data are structured as:
23+
```
24+
## MCP OUTPUT
25+
[Raw data from MCP tool execution]
26+
27+
## AI OUTPUT
28+
[AI analysis and interpretation of the tool results]
29+
```
30+
31+
This clear separation helps users distinguish between actual tool data and AI-generated insights.
32+
33+
## Supported MCP Tools
34+
35+
This example works with any MCP tools, but includes specific support for:
36+
- **OpenBB Docs Tools**: For querying OpenBB documentation
37+
- **Data Retrieval Tools**: For fetching structured data
38+
- **Analysis Tools**: For processing and analyzing information
1939

20-
## Getting started
40+
## How MCP Integration Works
41+
42+
1. **Tool Discovery**: Agent detects available MCP tools from connected servers
43+
2. **Schema Parsing**: Reads tool input schemas to understand required parameters
44+
3. **Function Definition**: Creates OpenAI function definitions for each tool
45+
4. **Execution Flow**:
46+
- User requests action requiring external data
47+
- Agent calls appropriate MCP tool with parameters
48+
- Frontend executes tool on MCP server
49+
- Results returned and formatted for user
50+
5. **Response Generation**: AI analyzes tool output and provides insights
51+
52+
## Getting Started
2153

2254
### Prerequisites
2355

24-
Ensure you have poetry, a tool for dependency management and packaging in Python, as well as your OpenAI API key.
56+
- Poetry for dependency management
57+
- OpenAI API key
58+
- MCP server with tools configured in OpenBB Terminal Pro
2559

2660
### Installation and Running
2761

2862
1. Clone this repository to your local machine.
2963

30-
2. Set the OpenAI API key as an environment variable in your .bashrc or .zshrc file:
64+
2. Set the OpenAI API key as an environment variable:
3165

3266
``` sh
3367
# in .zshrc or .bashrc
3468
export OPENAI_API_KEY=<your-api-key>
3569
```
3670

37-
3. Install the necessary dependencies:
71+
3. Install dependencies:
3872

3973
``` sh
4074
poetry install --no-root
@@ -43,22 +77,65 @@ poetry install --no-root
4377
4. Start the API server:
4478

4579
``` sh
46-
cd 37-vanilla-agent-custom-features
47-
poetry run uvicorn vanilla_agent_custom_features.main:app --port 7777 --reload
80+
cd 38-vanilla-agent-mcp-tools
81+
poetry run uvicorn vanilla_agent_mcp_tools.main:app --port 7777 --reload
4882
```
4983

50-
This command runs the FastAPI application, making it accessible on your network.
84+
### Testing MCP Integration
85+
86+
To test MCP tool functionality:
5187

52-
### Testing the Agent
88+
1. Ensure you have MCP tools configured in OpenBB Terminal Pro
89+
2. Ask the agent: "What MCP tools do you have available?"
90+
3. Request tool execution: "Use [tool_name] to search for [query]"
91+
4. Observe the structured output with MCP OUTPUT and AI OUTPUT sections
5392

54-
The example agent has a small, basic test suite to ensure it's working correctly. As you develop your agent, you are highly encouraged to expand these tests.
93+
### Running Tests
5594

56-
You can run the tests with:
95+
The agent includes tests for MCP tool integration:
5796

5897
```sh
5998
pytest tests
6099
```
61100

62-
### Accessing the Documentation
101+
### Configuration
102+
103+
The agent automatically configures MCP tool support through:
104+
- **Feature Flag**: `"mcp-tools": true` in the agent configuration
105+
- **Tool Detection**: Automatic discovery from `request.tools`
106+
- **Parameter Mapping**: Dynamic schema-based parameter validation
107+
108+
## API Documentation
109+
110+
Access the interactive API documentation at: http://localhost:7777/docs
111+
112+
## Example Usage
113+
114+
```
115+
User: "What MCP tools do you have available?"
116+
Agent: Lists all detected MCP tools with descriptions and parameters
117+
118+
User: "Use the docs tool to find information about widgets"
119+
Agent:
120+
## MCP OUTPUT
121+
[Documentation search results from MCP tool]
122+
123+
## AI OUTPUT
124+
Based on the documentation search, here's what I found about widgets...
125+
```
126+
127+
## Architecture
128+
129+
- **FastAPI Backend**: Handles requests and MCP tool orchestration
130+
- **OpenAI Integration**: Uses function calling for tool selection
131+
- **MCP Protocol**: Standard protocol for external tool communication
132+
- **Structured Output**: Clear separation of tool data and AI analysis
133+
134+
## Debugging
135+
136+
The agent includes comprehensive debugging output:
137+
- Tool discovery and server mapping
138+
- Parameter validation and transmission
139+
- Response processing and formatting
63140
64-
Once the API server is running, you can view the documentation and interact with the API by visiting: http://localhost:7777/docs
141+
Enable debug mode by checking server logs for `[DEBUG]` messages.

0 commit comments

Comments
 (0)