Created
April 19, 2025 11:35
-
-
Save PaulSec/66447e16175350366e3b61dcd717bd3d to your computer and use it in GitHub Desktop.
Simple MCP Server to request data from CFPTime.org
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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