Skip to content

Commit 57bced0

Browse files
authored
Add comprehensive testing documentation for shell scripts and Python agent (#113)
* Add comprehensive testing documentation for shell scripts and Python agent - Updated README.md with shell script testing options and Python agent reference - Created docs/testing.md with detailed testing guide covering: - Shell script testing (mcp_cmds.sh and mcp_demo.sh) for enterprise environments - Python agent testing (agents/agent.py) with advanced AI capabilities - Authentication setup with UI token generation instructions - Comparison between shell and Python approaches - Integration examples for CI/CD, Docker, and Kubernetes - Troubleshooting guides and enterprise use cases Addresses issue #112 - Enterprise Shell Script Support * Add shell scripts for enterprise MCP testing without Python dependencies - mcp_cmds.sh: Core MCP protocol operations using curl (ping, list, call tools) - mcp_demo.sh: Intelligent agent workflows with natural language queries Features: - Zero Python dependencies - uses only curl, jq, and standard Unix tools - Multiple authentication methods (env vars, JSON files, OAuth tokens) - Enterprise-ready with proxy support and minimal dependencies - Complete MCP protocol implementation with session management - Intelligent tool discovery and multi-step agent workflows - Works in restricted environments where Python packages cannot be installed Supports issue #112 requirements for enterprise environments with firewall restrictions and security policies that prevent external package installation. * Fix remote server URL example in testing documentation - Updated GATEWAY_URL example from https://your-server.com/mcp to https://your-server.com/currenttime/mcp - Ensures consistency with localhost example format and proper MCP server path structure
1 parent 84254ae commit 57bced0

File tree

4 files changed

+1275
-1
lines changed

4 files changed

+1275
-1
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,16 @@ open http://localhost:7860
275275

276276
**That's it!** Your enterprise MCP gateway is now running.
277277

278-
➡️ **Next Steps:** [Complete Installation Guide](docs/installation.md) | [Authentication Setup](docs/auth.md) | [AI Assistant Integration](docs/ai-coding-assistants-setup.md)
278+
### Testing & Integration Options
279+
280+
**Shell Scripts (No Python Required):**
281+
- `./mcp_cmds.sh` - Core MCP operations (ping, list tools, call tools)
282+
- `./mcp_demo.sh` - Intelligent agent workflows with natural language queries
283+
284+
**Python Agent:**
285+
- `agents/agent.py` - Full-featured Python agent with advanced AI capabilities
286+
287+
➡️ **Next Steps:** [Testing Guide](docs/testing.md) | [Complete Installation Guide](docs/installation.md) | [Authentication Setup](docs/auth.md) | [AI Assistant Integration](docs/ai-coding-assistants-setup.md)
279288

280289
---
281290

docs/testing.md

Lines changed: 363 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,363 @@
1+
# Testing MCP Gateway Registry
2+
3+
This guide covers different ways to test and interact with the MCP Gateway Registry, including both shell-based testing (no Python required) and Python agent testing.
4+
5+
## Testing Without Python
6+
7+
For enterprise environments with restricted package installation or when Python MCP packages are not available, use the provided shell scripts.
8+
9+
### Prerequisites
10+
11+
- `curl` - HTTP client (usually pre-installed)
12+
- `jq` - JSON processor (`sudo apt install jq` or `brew install jq`)
13+
- Standard Unix tools (`bash`, `sed`, `grep`)
14+
15+
### Shell Script Testing Tools
16+
17+
#### 1. `mcp_cmds.sh` - Core MCP Protocol Operations
18+
19+
Basic MCP server connectivity and tool operations using curl.
20+
21+
**Available Commands:**
22+
```bash
23+
# Test connectivity
24+
./mcp_cmds.sh ping
25+
26+
# List available tools
27+
./mcp_cmds.sh list
28+
29+
# Call a specific tool
30+
./mcp_cmds.sh call get_current_time
31+
32+
# Get help
33+
./mcp_cmds.sh help
34+
```
35+
36+
**With Authentication:**
37+
38+
Using environment variable (see [Authentication for Both Methods](#authentication-for-both-methods) section below):
39+
```bash
40+
USER_ACCESS_TOKEN=your_token ./mcp_cmds.sh list
41+
```
42+
43+
Using JSON token file:
44+
```bash
45+
# Place token in .oauth-tokens/user-token.json
46+
./mcp_cmds.sh list
47+
```
48+
49+
**Custom Server Targeting:**
50+
```bash
51+
# Target specific MCP server
52+
GATEWAY_URL=http://localhost/currenttime/mcp ./mcp_cmds.sh ping
53+
54+
# Target remote server
55+
GATEWAY_URL=https://your-server.com/currenttime/mcp ./mcp_cmds.sh list
56+
```
57+
58+
#### 2. `mcp_demo.sh` - Intelligent Agent Workflows
59+
60+
Demonstrates multi-step AI agent workflows using natural language queries.
61+
62+
**Available Commands:**
63+
```bash
64+
# Run full agent demo (default)
65+
./mcp_demo.sh demo
66+
67+
# Custom query and timezone
68+
./mcp_demo.sh demo "What time is it now?" "Europe/London"
69+
70+
# Just test tool discovery
71+
./mcp_demo.sh finder "time tools"
72+
73+
# Get help
74+
./mcp_demo.sh help
75+
```
76+
77+
**Agent Workflow Process:**
78+
1. **Query → Discovery**: Uses `intelligent_tool_finder` to find relevant tools
79+
2. **Tool Selection**: Parses response to identify appropriate server and tool
80+
3. **Server Switching**: Automatically switches to specific server context
81+
4. **Tool Execution**: Calls the identified tool with parameters
82+
5. **Result Extraction**: Processes and displays final results
83+
84+
**Example Output:**
85+
```bash
86+
$ ./mcp_demo.sh demo "What time is it now?" "Asia/Tokyo"
87+
88+
🤖 MCP Agent Demo - Mimicking agent.py workflow
89+
==================================
90+
Query: What time is it now?
91+
Timezone: Asia/Tokyo
92+
Gateway URL: http://localhost/mcpgw/mcp
93+
==================================
94+
95+
🔍 Step 1: Calling intelligent_tool_finder to discover time-related tools...
96+
🔍 Step 2: Parsing intelligent_tool_finder response...
97+
🕒 Step 3: Calling the identified tool...
98+
📋 Step 4: Extracting final result...
99+
🎉 Final Result: Current time in Asia/Tokyo: 2024-01-15 15:30:45 JST
100+
```
101+
102+
### Enterprise Use Cases
103+
104+
#### CI/CD Pipeline Integration
105+
```bash
106+
# Jenkins/GitLab CI step
107+
#!/bin/bash
108+
set -e
109+
export USER_ACCESS_TOKEN=$MCP_TOKEN
110+
./mcp_cmds.sh call validate_deployment '{"env":"staging"}'
111+
```
112+
113+
#### Automated Monitoring
114+
```bash
115+
# Cron job for system monitoring
116+
0 */4 * * * cd /opt/mcp && ./mcp_demo.sh demo "system status check"
117+
```
118+
119+
#### Quick Prototyping
120+
```bash
121+
# Test new MCP servers without Python setup
122+
./mcp_demo.sh finder "financial data tools"
123+
./mcp_cmds.sh call get_stock_price '{"symbol":"AAPL"}'
124+
```
125+
126+
### Troubleshooting Shell Scripts
127+
128+
**Authentication Issues:**
129+
```bash
130+
# Check if token is properly loaded
131+
echo $USER_ACCESS_TOKEN
132+
133+
# Verify token file exists and has correct format
134+
cat .oauth-tokens/user-token.json | jq .
135+
```
136+
137+
**Connectivity Issues:**
138+
```bash
139+
# Test basic connectivity
140+
curl -v http://localhost:7860/health
141+
142+
# Check if MCP server is responding
143+
./mcp_cmds.sh ping
144+
```
145+
146+
**JSON Parsing Issues:**
147+
```bash
148+
# Verify jq is installed
149+
jq --version
150+
151+
# Debug raw responses
152+
./mcp_cmds.sh list | grep "^data:" | sed 's/^data: //' | jq .
153+
```
154+
155+
## Python Agent Testing
156+
157+
For environments where Python packages can be installed, use the full-featured Python agent.
158+
159+
### Prerequisites
160+
161+
```bash
162+
# Install Python dependencies
163+
pip install -r agents/requirements.txt
164+
165+
# Or if using the project's environment
166+
cd agents && pip install -e .
167+
```
168+
169+
### Python Agent Features
170+
171+
The `agents/agent.py` provides advanced AI capabilities with LangGraph-based multi-turn conversations:
172+
173+
**Core Features:**
174+
- **LangGraph Integration**: Uses LangGraph reactive agents for complex reasoning
175+
- **Multi-Turn Conversations**: Maintains conversation history across interactions
176+
- **Anthropic Claude Integration**: Powered by ChatAnthropic for advanced language understanding
177+
- **MCP Tool Discovery**: Intelligent tool finder for dynamic tool selection
178+
- **Authentication Support**: Cognito-based authentication with token management
179+
- **Interactive Mode**: Real-time conversation interface with continuous interaction
180+
181+
**Available Tools:**
182+
- **`intelligent_tool_finder`**: AI-powered tool discovery using natural language
183+
- **`invoke_mcp_tool`**: Direct MCP tool invocation with authentication
184+
- **`calculator`**: Built-in mathematical expression evaluator
185+
186+
**Usage Examples:**
187+
188+
**Interactive Mode (Recommended):**
189+
```bash
190+
cd agents
191+
# Interactive session with conversation history
192+
python agent.py --interactive
193+
194+
# Interactive with initial prompt
195+
python agent.py --prompt "Hello, help me find time tools" --interactive
196+
```
197+
198+
**Single-Turn Mode:**
199+
```bash
200+
# Direct query execution
201+
python agent.py --prompt "What's the current time in New York?"
202+
203+
# Complex multi-step workflow
204+
python agent.py --prompt "Find financial tools and get Apple's stock price"
205+
```
206+
207+
**Authentication Options:**
208+
```bash
209+
# Environment variables (.env file recommended)
210+
COGNITO_CLIENT_ID=your_client_id
211+
COGNITO_CLIENT_SECRET=your_client_secret
212+
COGNITO_USER_POOL_ID=your_user_pool_id
213+
AWS_REGION=us-east-1
214+
ANTHROPIC_API_KEY=your_api_key
215+
216+
python agent.py --interactive
217+
218+
# Command line parameters
219+
python agent.py \
220+
--cognito-client-id your_client_id \
221+
--cognito-client-secret your_client_secret \
222+
--cognito-user-pool-id your_user_pool_id \
223+
--aws-region us-east-1 \
224+
--interactive
225+
```
226+
227+
**Advanced Configuration:**
228+
```bash
229+
# Custom server and model configuration
230+
python agent.py \
231+
--mcp-host localhost \
232+
--mcp-port 8000 \
233+
--model-id claude-3-5-sonnet-20241022 \
234+
--interactive
235+
236+
# With detailed logging
237+
python agent.py --prompt "test query" --verbose
238+
```
239+
240+
**Agent Workflow Process:**
241+
1. **Query Analysis**: Uses Claude to understand natural language intent
242+
2. **Tool Discovery**: Leverages `intelligent_tool_finder` for relevant tool identification
243+
3. **Multi-Step Execution**: Chains multiple MCP tool calls as needed
244+
4. **Context Maintenance**: Preserves conversation state across interactions
245+
5. **Error Handling**: Automatic retry with fallback strategies
246+
247+
### Python vs Shell Comparison
248+
249+
| Feature | Shell Scripts | Python Agent |
250+
|---------|--------------|---------------|
251+
| **Installation** | Zero dependencies | Requires pip packages |
252+
| **Enterprise Compatibility** | Works in restricted environments | May be blocked by firewalls |
253+
| **Functionality** | Core MCP operations | Advanced AI capabilities |
254+
| **Performance** | Fast, lightweight | More processing overhead |
255+
| **Complexity** | Simple, straightforward | Rich feature set |
256+
| **Error Handling** | Basic retry logic | Advanced recovery mechanisms |
257+
| **Use Case** | Testing, automation, CI/CD | Development, complex workflows |
258+
259+
### Authentication for Both Methods
260+
261+
**Environment Variable (Recommended):**
262+
```bash
263+
export USER_ACCESS_TOKEN=your_registry_token
264+
```
265+
266+
**Obtaining User Access Token:**
267+
You can generate a user access token from the MCP Gateway Registry UI by clicking the "Generate Token" dropdown menu item in the top right corner of the screen.
268+
269+
**Note:** If you are using an HTTPS URL for your MCP Gateway Registry, the token will be automatically looked up from the `.oauth-tokens/ingress.json` file.
270+
271+
**JSON Token File:**
272+
```json
273+
{
274+
"access_token": "your_token_here",
275+
"user_pool_id": "us-east-1_example",
276+
"client_id": "client_id_here",
277+
"region": "us-east-1"
278+
}
279+
```
280+
281+
**Token File Location:**
282+
- Place in `.oauth-tokens/user-token.json` relative to script location
283+
- Ensure proper JSON format and required fields
284+
285+
## Testing Scenarios
286+
287+
### Basic Connectivity Test
288+
```bash
289+
# Shell method
290+
./mcp_cmds.sh ping
291+
292+
# Python method
293+
cd agents && python agent.py "ping the system"
294+
```
295+
296+
### Tool Discovery Test
297+
```bash
298+
# Shell method
299+
./mcp_cmds.sh list
300+
301+
# Python method with intelligent discovery
302+
./mcp_demo.sh finder "available tools"
303+
```
304+
305+
### Complex Workflow Test
306+
```bash
307+
# Shell method - multi-step agent workflow
308+
./mcp_demo.sh demo "What's the weather like and what time is it?"
309+
310+
# Python method - advanced reasoning
311+
cd agents && python agent.py "Get current conditions and time for planning"
312+
```
313+
314+
## Integration Examples
315+
316+
### Docker Integration
317+
```dockerfile
318+
# Shell-based testing in container
319+
FROM ubuntu:22.04
320+
RUN apt-get update && apt-get install -y curl jq
321+
COPY mcp_cmds.sh mcp_demo.sh ./
322+
RUN chmod +x *.sh
323+
CMD ["./mcp_demo.sh", "demo"]
324+
```
325+
326+
### GitHub Actions
327+
```yaml
328+
name: MCP Integration Test
329+
on: [push, pull_request]
330+
jobs:
331+
test:
332+
runs-on: ubuntu-latest
333+
steps:
334+
- uses: actions/checkout@v3
335+
- name: Test MCP Gateway
336+
run: |
337+
export USER_ACCESS_TOKEN=${{ secrets.MCP_TOKEN }}
338+
./mcp_cmds.sh ping
339+
./mcp_demo.sh demo "system health check"
340+
```
341+
342+
### Kubernetes Job
343+
```yaml
344+
apiVersion: batch/v1
345+
kind: Job
346+
metadata:
347+
name: mcp-test
348+
spec:
349+
template:
350+
spec:
351+
containers:
352+
- name: mcp-test
353+
image: ubuntu:22.04
354+
command: ["/bin/bash", "-c"]
355+
args:
356+
- |
357+
apt-get update && apt-get install -y curl jq
358+
export USER_ACCESS_TOKEN=$MCP_TOKEN
359+
./mcp_cmds.sh list
360+
restartPolicy: Never
361+
```
362+
363+
This testing guide provides comprehensive coverage for both enterprise environments requiring shell-based testing and development environments where Python packages are available.

0 commit comments

Comments
 (0)