Skip to content

Commit ed452ac

Browse files
authored
Merge pull request #5 from baryhuang/add_global_tool_prompts
Add global tool prompt. That will help LLM accurately select your APIs.
2 parents 1562384 + 0e10e77 commit ed452ac

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

Diff for: README.md

+23-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55
## TODO
66
- The docker image is 2GB without pre-downloaded models. Its 3.76GB with pre-downloaded models!! Too big, someone please help me to reduce the size.
77

8+
## Configuration
9+
Customize through environment variables. **GLOBAL_TOOL_PROMPT** is **IMPORTANT**!
10+
11+
- `OPENAPI_JSON_DOCS_URL`: URL to the OpenAPI specification JSON (defaults to https://api.staging.readymojo.com/openapi.json)
12+
- `MCP_API_PREFIX`: Customizable tool namespace (default "any_openapi"):
13+
```bash
14+
# Creates tools: custom_api_request_schema and custom_make_request
15+
docker run -e MCP_API_PREFIX=finance ...
16+
```
17+
- `GLOBAL_TOOL_PROMPT`: Optional text to prepend to all tool descriptions. This is crucial to make the Claude select and not select your tool accurately.
18+
```bash
19+
# Adds "Access to insights apis for ACME Financial Services abc.com . " to the beginning of all tool descriptions
20+
docker run -e GLOBAL_TOOL_PROMPT="Access to insights apis for ACME Financial Services abc.com ." ...
21+
```
22+
823
## TL'DR
924
**Why I create this**: I want to serve my private API, whose swagger openapi docs is a few hundreds KB in size.
1025
- Claude MCP simply error on processing these size of file
@@ -58,6 +73,8 @@ Here is the multi-instance config example. I design it so it can more flexibly u
5873
"OPENAPI_JSON_DOCS_URL=https://api.finance.com/openapi.json",
5974
"-e",
6075
"MCP_API_PREFIX=finance",
76+
"-e",
77+
"GLOBAL_TOOL_PROMPT='Access to insights apis for ACME Financial Services abc.com .'",
6178
"buryhuang/mcp-server-any-openapi:latest"
6279
]
6380
},
@@ -71,6 +88,8 @@ Here is the multi-instance config example. I design it so it can more flexibly u
7188
"OPENAPI_JSON_DOCS_URL=https://api.healthcare.com/openapi.json",
7289
"-e",
7390
"MCP_API_PREFIX=healthcare",
91+
"-e",
92+
"GLOBAL_TOOL_PROMPT='Access to insights apis for Healthcare API services efg.com .",
7493
"buryhuang/mcp-server-any-openapi:latest"
7594
]
7695
}
@@ -98,6 +117,8 @@ In this example:
98117
"API_REQUEST_BASE_URL=https://api.finance.staging.com",
99118
"-e",
100119
"MCP_API_PREFIX=finance",
120+
"-e",
121+
"GLOBAL_TOOL_PROMPT='Access to insights apis for ACME Financial Services abc.com .'",
101122
"buryhuang/mcp-server-any-openapi:latest"
102123
]
103124
}
@@ -137,16 +158,6 @@ npx -y @smithery/cli install @baryhuang/mcp-server-any-openapi --client claude
137158
pip install mcp-server-any-openapi
138159
```
139160

140-
## Configuration
141-
142-
Customize through environment variables:
143-
144-
- `OPENAPI_JSON_DOCS_URL`: URL to the OpenAPI specification JSON (defaults to https://api.staging.readymojo.com/openapi.json)
145-
- `MCP_API_PREFIX`: Customizable tool namespace (default "any_openapi"):
146-
```bash
147-
# Creates tools: custom_api_request_schema and custom_make_request
148-
docker run -e MCP_API_PREFIX=finance ...
149-
```
150161

151162
## Available Tools
152163

@@ -296,6 +307,8 @@ Configure the MCP server in your Claude Desktop settings:
296307
"OPENAPI_JSON_DOCS_URL=https://api.example.com/openapi.json",
297308
"-e",
298309
"MCP_API_PREFIX=finance",
310+
"-e",
311+
"GLOBAL_TOOL_PROMPT='Access to insights apis for ACME Financial Services abc.com .",
299312
"buryhuang/mcp-server-any-openapi:latest"
300313
]
301314
}

Diff for: src/mcp_server_any_openapi/server.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,19 @@ async def main():
220220
api_prefix = os.getenv('MCP_API_PREFIX', 'any_openapi')
221221
server = Server(api_prefix)
222222
endpoint_searcher = EndpointSearcher()
223+
224+
# Get global tool prompt from environment variable
225+
global_tool_prompt = os.getenv('GLOBAL_TOOL_PROMPT', '')
226+
if global_tool_prompt and not global_tool_prompt.endswith(' '):
227+
global_tool_prompt += ' ' # Add space if not already present
223228

224229
@server.list_tools()
225230
async def handle_list_tools() -> list[types.Tool]:
226231
"""List available tools"""
227232
return [
228233
types.Tool(
229234
name=f"{api_prefix}_api_request_schema",
230-
description="Get API endpoint schemas that match your intent. Returns endpoint details including path, method, parameters, and response formats.",
235+
description=f"{global_tool_prompt} Get API endpoint schemas that match your intent. Returns endpoint details including path, method, parameters, and response formats.",
231236
inputSchema={
232237
"type": "object",
233238
"properties": {
@@ -241,7 +246,7 @@ async def handle_list_tools() -> list[types.Tool]:
241246
),
242247
types.Tool(
243248
name=f"{api_prefix}_make_request",
244-
description="Make an actual REST API request with full control over method, headers, body, and parameters.",
249+
description=f"{global_tool_prompt} Make an actual REST API request with full control over method, headers, body, and parameters.",
245250
inputSchema={
246251
"type": "object",
247252
"properties": {

0 commit comments

Comments
 (0)