Skip to content

Instantly share code, notes, and snippets.

@PaulSec
Created April 19, 2025 11:35
Show Gist options
  • Save PaulSec/66447e16175350366e3b61dcd717bd3d to your computer and use it in GitHub Desktop.
Save PaulSec/66447e16175350366e3b61dcd717bd3d to your computer and use it in GitHub Desktop.
Simple MCP Server to request data from CFPTime.org
# server.py
from mcp.server.fastmcp import FastMCP
import requests
import json
# Create an MCP server
mcp = FastMCP("Demo")
# Simplify and improve error handling for retrieving CFPs
@mcp.tool()
async def retrieve_all_cfps() -> str:
"""Retrieve CFPs from an external API"""
url = "https://api.cfptime.org/api/cfps/"
headers = {"Accept": "application/json", "User-Agent": "Mozilla/5.0"}
try:
response = requests.get(url, headers=headers)
response.raise_for_status() # Raise an HTTPError for bad responses (4xx and 5xx)
data = response.json() # Parse JSON response
return json.dumps({"success": True, "data": data})
except requests.exceptions.RequestException as e:
return json.dumps({"success": False, "error": str(e)})
except json.JSONDecodeError as e:
return json.dumps({"success": False, "error": f"JSON parsing error: {str(e)}"})
@mcp.tool()
async def retrieve_upcoming_conferences() -> str:
"""Retrieve all upcoming conferences from an external API"""
url = "https://api.cfptime.org/api/upcoming/"
headers = {"Accept": "application/json", "User-Agent": "Mozilla/5.0"}
try:
response = requests.get(url, headers=headers)
response.raise_for_status() # Raise an HTTPError for bad responses (4xx and 5xx)
data = response.json() # Parse JSON response
return json.dumps({"success": True, "data": data})
except requests.exceptions.RequestException as e:
return json.dumps({"success": False, "error": str(e)})
except json.JSONDecodeError as e:
return json.dumps({"success": False, "error": f"JSON parsing error: {str(e)}"})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment