Spaces:
Sleeping
Sleeping
Raghav Samavedam commited on
Commit ·
0f04aed
0
Parent(s):
Initial commit: CRO MCP Server for ChatGPT Custom Connectors
Browse filesFiles changed (4)
- DockerfileAdded+21
- README.mdAdded+59
- app.pyAdded+208
- requirements.txtAdded+3
123456789101112131415161718192021FROM python:3.11-slim
WORKDIR /app
# Install dependenciesCOPY mcp_requirements.txt requirements.txtRUN pip install --no-cache-dir -r requirements.txtRUN pip install fastapi uvicorn httpx
# Copy the MCP serverCOPY mcp_server_web.py .
# Set environment variablesENV PORT=7860ENV PYTHONUNBUFFERED=1
# Expose portEXPOSE 7860
# Run the MCP serverCMD ["python", "-m", "uvicorn", "mcp_server_web:app", "--host", "0.0.0.0", "--port", "7860"]1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859---title: CRO MCP Serveremoji: 🔌colorFrom: purplecolorTo: bluesdk: dockerpinned: falselicense: mit---
# CRO MCP Server
MCP (Model Context Protocol) server wrapper for the CRO Mock API. This enables integration with ChatGPT Custom Connectors and Claude Desktop.
## Features
- **MCP Protocol Support**: Implements the MCP protocol for tool discovery and execution- **9 CRO Tools**: All endpoints from the mock API available as MCP tools- **ChatGPT Compatible**: Use with Custom Connectors (beta)- **Claude Compatible**: Works with Claude Desktop MCP integration
## Endpoints
- `POST /` - Main MCP endpoint- `GET /` - Server info- `GET /health` - Health check
## MCP Methods Supported
- `initialize` - Initialize connection- `tools/list` - List available tools- `tools/call` - Execute a tool- `resources/list` - List resources- `resources/read` - Read resource content
## Tools Available
1. `list_cros` - List CRO vendors by capability2. `draft_protocol` - Create protocols from objectives3. `request_quote` - Get quotes from CROs4. `submit_order` - Place orders5. `check_status` - Monitor progress6. `upload_artifacts` - Upload documents7. `download_results` - Get results8. `cancel_order` - Cancel orders
## Integration
### ChatGPT Custom Connectors1. Use this URL as MCP Server URL: `https://raghavsam-cro-mcp-server.hf.space`2. Authentication: None3. The connector will discover tools automatically
### Testing```bashcurl -X POST https://raghavsam-cro-mcp-server.hf.space \ -H "Content-Type: application/json" \ -d '{"method": "tools/list"}'```123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208#!/usr/bin/env python3"""Web-based MCP Server for ChatGPT Custom ConnectorsProvides HTTP endpoints that mimic MCP protocol"""
from fastapi import FastAPI, HTTPExceptionfrom fastapi.middleware.cors import CORSMiddlewarefrom pydantic import BaseModelfrom typing import Any, Dict, List, Optionalimport httpximport jsonimport os
app = FastAPI(title="CRO MCP Server")
# Add CORS for ChatGPTapp.add_middleware( CORSMiddleware, allow_origins=["https://chat.openai.com", "*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"],)
# Your deployed APIAPI_BASE_URL = "https://raghavsam-mcp-cro-mock.hf.space"
class MCPRequest(BaseModel): method: str params: Optional[Dict[str, Any]] = {}
class ToolCallParams(BaseModel): name: str arguments: Dict[str, Any]
@app.get("/")async def root(): """MCP server info""" return { "mcp_version": "0.9.1", "server_name": "cro-mock-mcp", "capabilities": ["tools", "resources"] }
@app.post("/")async def handle_mcp_request(request: MCPRequest): """Main MCP endpoint - handles all MCP requests""" if request.method == "initialize": return { "protocolVersion": "0.9.1", "serverInfo": { "name": "cro-mock-mcp", "version": "1.0.0" }, "capabilities": { "tools": {}, "resources": {} } } elif request.method == "tools/list": return { "tools": [ { "name": "list_cros", "description": "List CRO vendors filtered by capabilities", "inputSchema": { "type": "object", "properties": { "capability_filter": { "type": "array", "items": {"type": "string"} }, "region": {"type": "string", "enum": ["US", "EU", "ANY"]} } } }, { "name": "draft_protocol", "description": "Convert objectives to protocols", "inputSchema": { "type": "object", "required": ["objective", "inputs"], "properties": { "objective": {"type": "string"}, "inputs": {"type": "object"} } } }, { "name": "request_quote", "description": "Get quotes from CROs", "inputSchema": { "type": "object", "required": ["protocol_id", "targets"], "properties": { "protocol_id": {"type": "string"}, "targets": {"type": "array", "items": {"type": "string"}}, "speed_vs_cost": {"type": "string"} } } }, { "name": "submit_order", "description": "Submit order to CRO", "inputSchema": { "type": "object", "required": ["rfq_id", "selected_cro", "po_ref", "billing", "ship_to"], "properties": { "rfq_id": {"type": "string"}, "selected_cro": {"type": "string"}, "po_ref": {"type": "string"}, "billing": {"type": "object"}, "ship_to": {"type": "object"} } } }, { "name": "check_status", "description": "Check order status", "inputSchema": { "type": "object", "required": ["order_id"], "properties": {"order_id": {"type": "string"}} } } ] } elif request.method == "tools/call": # Extract parameters params = request.params tool_name = params.get("name") arguments = params.get("arguments", {}) # Call the actual API async with httpx.AsyncClient() as client: try: response = await client.post( f"{API_BASE_URL}/{tool_name}", json=arguments, timeout=30.0 ) result = response.json() return { "content": [ { "type": "text", "text": json.dumps(result, indent=2) } ] } except Exception as e: return { "error": { "type": "api_error", "message": f"Failed to call {tool_name}: {str(e)}" } } elif request.method == "resources/list": return { "resources": [ { "uri": "cro://status", "name": "API Status", "description": "Check CRO API status", "mimeType": "application/json" } ] } elif request.method == "resources/read": uri = request.params.get("uri") if uri == "cro://status": async with httpx.AsyncClient() as client: try: response = await client.get(API_BASE_URL) return { "contents": [ { "uri": uri, "text": json.dumps({ "status": "operational", "api": API_BASE_URL, "data": response.json() }, indent=2) } ] } except: return {"contents": [{"uri": uri, "text": '{"status": "error"}'}]} else: raise HTTPException(status_code=404, detail=f"Unknown method: {request.method}")
# Health check for deployment@app.get("/health")async def health(): return {"status": "healthy"}
if __name__ == "__main__": import uvicorn port = int(os.environ.get("PORT", 8000)) uvicorn.run(app, host="0.0.0.0", port=port)123mcp==0.9.1aiohttp==3.9.1python-dotenv==1.0.0DockerfileAdded+21
README.mdAdded+59
app.pyAdded+208
requirements.txtAdded+3