Skip to content

Commit ab37d4b

Browse files
Agentic behaviour to call guide before anything else (#4)
1 parent be5547d commit ab37d4b

File tree

2 files changed

+72
-54
lines changed

2 files changed

+72
-54
lines changed

README.md

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This MCP (Model Context Protocol) Server provides seamless integration with the
2929

3030
| Tool Name | Description |
3131
| --------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
32+
| `FIRST_STEP_get_api_script_guide` | **🚀 Start here!** Loads comprehensive API script generation guide - call this tool first before using others. |
3233
| `refresh_api_catalog` | Refreshes the API catalog by fetching the latest OpenAPI specification from the control plane. |
3334
| `search_api_operations` | Search for operations using fuzzy matching across operation IDs, summaries, descriptions, and tags. |
3435
| `search_api_schemas` | Search for schemas by name and description to find relevant data structures. |
@@ -65,7 +66,7 @@ Add the following to your `claude_desktop_config.json`:
6566
"command": "uv",
6667
"args": ["run", "--directory", "/path/to/your/cloned/control-plane-openapi-mcp", "control-plane-openapi-mcp"],
6768
"env": {
68-
"CONTROL_PLANE_URL": "https://facetsdemo.console.facets.cloud",
69+
"CONTROL_PLANE_URL": "https://<customername>.console.facets.cloud",
6970
"FACETS_USERNAME": "<YOUR_USERNAME>",
7071
"FACETS_TOKEN": "<YOUR_TOKEN>",
7172
"FACETS_PROFILE": "default",
@@ -97,11 +98,10 @@ For credential setup, refer to the [Facets Authentication Guide](https://readme.
9798

9899
## Usage Highlights
99100

100-
- Use `search_api_operations` and `search_api_schemas` to find relevant endpoints using natural language
101-
- Use specific load operations to get detailed parameter and response information
102-
- Use `call_control_plane_api` to make actual API calls and get real data from your Facets environment
103-
- Leverage the fuzzy search to find operations even with partial or approximate terms
104-
- All results exclude deprecated operations for cleaner, more relevant responses
101+
- Uses `search_api_operations` and `search_api_schemas` to find relevant endpoints using natural language
102+
- Uses specific load operations to get detailed parameter and response information
103+
- Uses `call_control_plane_api` to make actual API calls and get real data from your Facets environment
104+
- Leverages the fuzzy search to find operations even with partial or approximate terms
105105

106106
## API Coverage
107107

@@ -120,15 +120,15 @@ The server provides access to the complete Facets Control Plane API including:
120120
When using with Claude, try these example prompts:
121121

122122
```
123-
"Show me all stack-related operations in the Facets API"
124-
"What are the required parameters for creating a new stack?"
125-
"Find operations related to cluster deployments"
126-
"Show me the Stack schema structure with all its properties"
127-
"Generate a TypeScript interface for the Stack model"
128-
"Get the current list of stacks from my environment"
129-
"Show me details of a specific stack named 'my-production-stack'"
130-
"What clusters are running in my Facets environment?"
131-
"Create an example API call to get stack information"
123+
"Show me all project-related operations in the Facets API"
124+
"What are the required parameters for creating a new project?"
125+
"Find operations related to environment deployments"
126+
"Show me the project schema structure with all its properties"
127+
"Generate a TypeScript interface for the project model"
128+
"Get the current list of projects from my environment"
129+
"Show me details of a specific project named 'my-production-project'"
130+
"What environments are running in my Facets environment?"
131+
"Create an example API call to get project information"
132132
"Find all endpoints that handle artifact routing"
133133
"What authentication methods are available in the API?"
134134
```
@@ -155,24 +155,6 @@ When using with Claude, try these example prompts:
155155
.venv\Scripts\activate # On Windows
156156
```
157157

158-
### Running Tests
159-
160-
```bash
161-
# Run the example script to test functionality
162-
uv run python example.py
163-
164-
# Test direct tool imports
165-
uv run python test_final.py
166-
167-
# Test specific functionality
168-
uv run python -c "
169-
from control_plane_openapi_mcp.tools import search_api_operations
170-
import json
171-
result = search_api_operations('stack')
172-
print(f'Found {len(json.loads(result)[\"operations\"])} operations')
173-
"
174-
```
175-
176158
### Testing the MCP Server
177159

178160
```bash
@@ -210,34 +192,14 @@ control_plane_openapi_mcp/
210192

211193
---
212194

213-
## Example Usage
214-
215-
For comprehensive examples of API exploration and integration, check out the included scripts:
216-
217-
- **`example.py`**: Demonstrates all available tools with real API data
218-
- **`test_final.py`**: Validates functionality and shows expected results
219-
220-
These examples show the complete workflow from API discovery to detailed operation analysis.
221-
222-
---
223-
224195
## Architecture
225196

226197
- **`SpecLoader`**: Fetches and processes OpenAPI specifications with JSON reference resolution
227198
- **`SpecProcessor`**: Extracts operations and schemas while filtering deprecated endpoints
228199
- **`SearchEngine`**: Provides fuzzy search capabilities with configurable matching thresholds
229200
- **`OpenAPIService`**: Main service coordinating all components with intelligent caching
230201
- **`SimpleCache`**: TTL-based caching for performance optimization
231-
- **MCP Tools**: Seven specialized tools exposing functionality to AI assistants
232-
233-
## Comparison with TypeScript Version
234-
235-
This Python implementation provides similar functionality to the TypeScript `@reapi/mcp-openapi` but is:
236-
237-
- **Simpler**: Single API spec focus, no file system operations required
238-
- **Focused**: Specifically designed for Facets Control Plane integration
239-
- **Efficient**: Direct JSON processing with smart caching strategies
240-
- **Lightweight**: Fewer dependencies and cleaner abstractions
202+
- **MCP Tools**: Specialized tools exposing functionality to AI assistants
241203

242204
## License
243205

control_plane_openapi_mcp/tools.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import logging
3+
import os
34

45
from .config import mcp, OPENAPI_URL, CACHE_TTL, SPEC_ID
56
from .core.service import OpenAPIService
@@ -24,9 +25,58 @@
2425
logger.info("API client not available - only OpenAPI exploration tools will work")
2526

2627

28+
@mcp.resource(uri="resource://control_plane_api_knowledge", name="Control Plane API Knowledge Base")
29+
def call_always_for_instruction() -> str:
30+
return FIRST_STEP_get_api_script_guide()
31+
32+
33+
@mcp.tool()
34+
def FIRST_STEP_get_api_script_guide() -> str:
35+
"""
36+
<important>ALWAYS Call this tool first before calling any other tool of this mcp.</important>
37+
Loads the API script generation guide that contains comprehensive instructions for creating
38+
scripts that interact with Control Plane APIs.
39+
40+
Returns:
41+
str: A JSON string containing the content of the API script guide.
42+
"""
43+
try:
44+
# Get the directory where this file is located
45+
current_dir = os.path.dirname(__file__)
46+
guide_path = os.path.join(current_dir, "prompts", "api_script_guide.md")
47+
48+
# Read the guide content
49+
with open(guide_path, 'r', encoding='utf-8') as f:
50+
guide_content = f.read()
51+
52+
return json.dumps({
53+
"success": True,
54+
"message": "API script guide loaded successfully.",
55+
"instructions": "Inform User: API script guide loaded successfully.",
56+
"data": {
57+
"api_script_guide.md": guide_content
58+
}
59+
}, indent=2)
60+
61+
except FileNotFoundError:
62+
return json.dumps({
63+
"success": False,
64+
"message": "API script guide file not found.",
65+
"error": f"Could not find api_script_guide.md at {guide_path}"
66+
}, indent=2)
67+
68+
except Exception as e:
69+
return json.dumps({
70+
"success": False,
71+
"message": "Failed to load API script guide.",
72+
"error": str(e)
73+
}, indent=2)
74+
75+
2776
@mcp.tool()
2877
def refresh_api_catalog() -> str:
2978
"""
79+
<important>Make Sure you have Called FIRST_STEP_get_api_script_guide first before this tool.</important>
3080
Refresh the API catalog by fetching the latest OpenAPI specification.
3181
3282
Returns:
@@ -49,6 +99,7 @@ def refresh_api_catalog() -> str:
4999
@mcp.tool()
50100
def search_api_operations(query: str) -> str:
51101
"""
102+
<important>Make Sure you have Called FIRST_STEP_get_api_script_guide first before this tool.</important>
52103
Search for operations across the OpenAPI specification using fuzzy matching.
53104
54105
Note: Only searches through active (non-deprecated) operations.
@@ -89,6 +140,7 @@ def search_api_operations(query: str) -> str:
89140
@mcp.tool()
90141
def search_api_schemas(query: str) -> str:
91142
"""
143+
<important>Make Sure you have Called FIRST_STEP_get_api_script_guide first before this tool.</important>
92144
Search for schemas across the OpenAPI specification using fuzzy matching.
93145
94146
Args:
@@ -146,6 +198,7 @@ def _format_operation_response(operation) -> str:
146198
@mcp.tool()
147199
def load_api_operation_by_operationId(operation_id: str) -> str:
148200
"""
201+
<important>Make Sure you have Called FIRST_STEP_get_api_script_guide first before this tool.</important>
149202
Load a specific operation by its operationId.
150203
151204
Args:
@@ -168,6 +221,7 @@ def load_api_operation_by_operationId(operation_id: str) -> str:
168221
@mcp.tool()
169222
def load_api_operation_by_path_and_method(path: str, method: str) -> str:
170223
"""
224+
<important>Make Sure you have Called FIRST_STEP_get_api_script_guide first before this tool.</important>
171225
Load a specific operation by its path and HTTP method.
172226
173227
Args:
@@ -191,6 +245,7 @@ def load_api_operation_by_path_and_method(path: str, method: str) -> str:
191245
@mcp.tool()
192246
def load_api_schema_by_schemaName(schema_name: str) -> str:
193247
"""
248+
<important>Make Sure you have Called FIRST_STEP_get_api_script_guide first before this tool.</important>
194249
Load a specific schema by its name.
195250
196251
Args:
@@ -228,6 +283,7 @@ def load_api_schema_by_schemaName(schema_name: str) -> str:
228283
@mcp.tool()
229284
def call_control_plane_api(path: str) -> str:
230285
"""
286+
<important>Make Sure you have Called FIRST_STEP_get_api_script_guide first before this tool.</important>
231287
Make a GET request to the Facets Control Plane API.
232288
233289
Args:

0 commit comments

Comments
 (0)