example_usage.py•3.65 kB
#!/usr/bin/env python3
"""
Example script showing how to use the NFL Transactions MCP with a super agent.
This demonstrates sending JSON-RPC requests and processing responses.
"""
import json
import subprocess
import sys
import os
def call_mcp(method, params=None):
"""
Call an MCP method via subprocess.
Args:
method: The method name to call
params: Dictionary of parameters
Returns:
Parsed JSON response
"""
request = {
"jsonrpc": "2.0",
"method": method,
"params": params or {},
"id": 1
}
# In a real integration, you'd use Cursor's run-mcp command
# But for testing/example purposes, we'll directly call the server
server_path = os.path.join(os.path.dirname(__file__), "server.py")
cmd = [sys.executable, server_path]
# Start the process
proc = subprocess.Popen(
cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
text=True
)
# Send the request and get the response
print(f"Sending request: {json.dumps(request)}")
stdout, _ = proc.communicate(json.dumps(request))
# Parse response lines (there might be debug output mixed in)
response = None
for line in stdout.splitlines():
try:
parsed = json.loads(line)
if "jsonrpc" in parsed and "id" in parsed:
response = parsed
break
except json.JSONDecodeError:
continue
return response
def main():
"""Run example MCP calls"""
print("NFL Transactions MCP Example Usage\n")
# Example 1: List available tools
print("Example 1: Listing available tools")
tools_response = call_mcp("listTools")
if tools_response and "result" in tools_response:
tools = tools_response["result"]["tools"]
print(f"Available tools: {', '.join(t['name'] for t in tools)}")
else:
print(f"Error listing tools: {tools_response}")
# Example 2: List NFL teams
print("\nExample 2: Listing NFL teams")
teams_response = call_mcp("list_teams")
if teams_response and "result" in teams_response:
teams = teams_response["result"]["teams"]
print(f"Found {len(teams)} teams. First 5: {', '.join(teams[:5])}")
else:
print(f"Error listing teams: {teams_response}")
# Example 3: List transaction types
print("\nExample 3: Listing transaction types")
types_response = call_mcp("list_transaction_types")
if types_response and "result" in types_response:
types = types_response["result"]["transaction_types"]
print(f"Available transaction types: {', '.join(types)}")
else:
print(f"Error listing transaction types: {types_response}")
# Example 4: Fetch transactions
print("\nExample 4: Fetching Patriots injury transactions from January 2023")
params = {
"team": "Patriots",
"start_date": "2023-01-01",
"end_date": "2023-01-31",
"transaction_type": "Injury",
"output_format": "json"
}
txn_response = call_mcp("fetch_transactions", params)
if txn_response and "result" in txn_response:
result = txn_response["result"]
data = result.get("data", [])
print(f"Found {len(data)} transactions")
if data:
# Display first transaction
print("\nFirst transaction:")
for key, value in data[0].items():
print(f" {key}: {value}")
else:
print(f"Error fetching transactions: {txn_response}")
if __name__ == "__main__":
main()