Skip to main content
Glama

MCP Blog API

by tussanakorn
main.py944 B
from typing import Any import httpx from mcp.server.fastmcp import FastMCP from dotenv import load_dotenv import os # Load environment variables from .env file load_dotenv() # Initialize FastMCP server mcp = FastMCP("mcp-blog") # Get the mock API URL from environment variables mock_api_url = os.getenv("MOCK_API_URL") @mcp.tool() def get_blogs(): """Fetch all blogs from the mock API.""" response = httpx.get(mock_api_url) return response.json() @mcp.tool() def search_blogs(query: str): """Search for blogs by title using the mock API.""" response = httpx.get(mock_api_url, params={'title': query}) return response.json() @mcp.tool() def add_blog(title: str, body: str): """Add a new blog to the mock API.""" response = httpx.post(mock_api_url, json={'title': title, 'body': body}) return response.json() if __name__ == "__main__": # Initialize and run the server mcp.run(transport='stdio')

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tussanakorn/POC_MCP_Protocol_using_FastMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server