### Get Author Keywords Response Example (Success) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/endpoints.md Example JSON response when keywords are successfully retrieved, including author details and a list of keywords. ```json { "success": true, "author": "Geoffrey Hinton", "institution": "University of Toronto", "source": "Google Scholar", "total_keywords": 4, "keywords": [ "deep learning", "neural networks", "machine learning", "backpropagation" ] } ``` -------------------------------- ### Docker Run Commands Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Examples of how to run the Docker container with custom ports and host bindings, useful for reverse proxy setups. ```bash # Run container with custom port docker run -e PORT=3000 -p 3000:3000 authorprofile:latest # Run with custom host (for reverse proxy) docker run -e HOST=127.0.0.1 -e PORT=8080 authorprofile:latest ``` -------------------------------- ### MCP Client Integration (Python Async) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/MANIFEST.md Illustrates integrating the MCP client for making requests, likely for a different service or a more abstract client interaction. This example assumes a client setup. ```python import asyncio from author_profile_mcp.client import MCPClient async def main(): async with MCPClient() as client: coauthors = await client.get_coauthors("Alperen", "Koçyiğit", "Sabancı University") print(coauthors) if __name__ == "__main__": asyncio.run(main()) ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/README.md Installs all necessary Python packages listed in the requirements.txt file. ```bash pip install -r requirements.txt ``` -------------------------------- ### Build and Run Docker Image Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/MANIFEST.md Instructions for building the Docker image for the Author Profile MCP and running it as a container. Assumes Docker is installed. ```shell # Build the Docker image docker build -t author-profile-mcp . # Run the Docker container docker run -p 8000:8000 author-profile-mcp ``` -------------------------------- ### Local Development: STDIO Server Start Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Starts the local server using STDIO for communication. No environment variables are required for this mode. ```bash # No environment variables needed python server.py ``` -------------------------------- ### Get Author Keywords Request Example Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/endpoints.md Example JSON payload for requesting author keywords, specifying name, surname, and optionally institution. ```json { "name": "Geoffrey", "surname": "Hinton", "institution": "University of Toronto" } ``` -------------------------------- ### FastMCP Server Entry Point Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Demonstrates the basic setup for a FastMCP server instance, including defining tools and running the server with different transport modes. ```Python # server.py from mcp.server.fastmcp import FastMCP from search import AuthorSearchEngine mcp = FastMCP("authorProfile") search_engine = AuthorSearchEngine() @mcp.tool() async def get_coauthors(...): ... @mcp.tool() async def get_author_keywords(...): ... if __name__ == "__main__": transport = os.getenv("TRANSPORT", "stdio") if transport == "http": uvicorn.run(mcp.streamable_http_app, ...) else: mcp.run() ``` -------------------------------- ### Get Author Keywords Response Example (Error) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/endpoints.md Example JSON response when an error occurs during keyword retrieval, indicating failure and providing an error message. ```json { "success": false, "error": "Error message describing what went wrong", "keywords": [] } ``` -------------------------------- ### Local Development: HTTP Server Start and Test Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Starts the local server using HTTP transport and provides a curl command to test the 'get_coauthors' endpoint. ```bash TRANSPORT=http PORT=8081 python server.py # Test: curl -X POST http://localhost:8081/invoke/get_coauthors \ -H "Content-Type: application/json" \ -d '{"name":"Albert","surname":"Einstein"}' ``` -------------------------------- ### Run the MCP Server Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/README.md Starts the Academic Author Network MCP Server. This command should be run from the project's root directory. ```bash python server.py ``` -------------------------------- ### Python MCP Client Example for Get Author Keywords Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/endpoints.md Illustrates using the MCP client library in Python to asynchronously call the get_author_keywords tool and handle the results. ```python import asyncio from mcp import Client async def main(): async with Client("http://localhost:8081") as client: result = await client.invoke_tool( "get_author_keywords", { "name": "Yann", "surname": "LeCun" } ) if result['success']: for keyword in result['keywords']: print(keyword) else: print(f"Error: {result['error']}") asyncio.run(main()) ``` -------------------------------- ### Example HTTP Server Command Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/server.md This bash command shows how to launch the HTTP server on a specific port and host. It sets the necessary environment variables for TRANSPORT, PORT, and HOST. ```bash # Run HTTP server on port 8081 TRANSPORT=http PORT=8081 HOST=0.0.0.0 python server.py ``` -------------------------------- ### POST /invoke/get_coauthors Request Body Example Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/endpoints.md Example of a JSON request body to get co-authors for 'Yann LeCun' from NYU. ```json { "name": "Yann", "surname": "LeCun", "institution": "NYU" } ``` -------------------------------- ### POST /invoke/get_coauthors Response Body Example (Success) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/endpoints.md Example of a successful JSON response body containing co-author information. ```json { "success": true, "author": "Yann LeCun", "institution": "NYU", "total_coauthors": 2, "coauthors": [ { "name": "Yoshua Bengio", "collaborations": 15, "source": "semantic_scholar" }, { "name": "Geoffrey Hinton", "collaborations": 8, "source": "semantic_scholar" } ] } ``` -------------------------------- ### Python Requests Example for Get Author Keywords Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/endpoints.md Shows how to use the Python 'requests' library to invoke the get_author_keywords endpoint and process the JSON response. ```python import requests response = requests.post( 'http://localhost:8081/invoke/get_author_keywords', json={ 'name': 'Andrew', 'surname': 'Ng' } ) result = response.json() if result['success']: print(f"Found {result['total_keywords']} keywords:") for keyword in result['keywords']: print(f" - {keyword}") else: print(f"Error: {result['error']}") ``` -------------------------------- ### Success Response Example Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Illustrates the JSON structure for a successful operation, including author details and co-author count. ```json { "success": true, "author": "...", "total_coauthors": 42, "coauthors": [...] } ``` -------------------------------- ### Run Server in HTTP Mode Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Starts the server using HTTP transport, configured for Smithery deployment. Sets the transport mode, port, and host. ```bash TRANSPORT=http PORT=8081 HOST=0.0.0.0 python server.py ``` -------------------------------- ### Cache Key Generation Example Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Demonstrates how cache keys are generated using an MD5 hash of function arguments. Used for memoization in author data retrieval. ```python # get_coauthors call key = _get_cache_key('coauthors', 'Marie', 'Curie', 'University of Paris', None) # Returns: '5d41402abc4b2a76b9719d911017c592' # get_author_keywords call key = _get_cache_key('keywords', 'Albert', 'Einstein', 'Princeton') # Returns: '6d51402abc4b2a76b9719d911017c593' ``` -------------------------------- ### Python Example using MCP client for POST /invoke/get_coauthors Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/endpoints.md Illustrates how to use the MCP client library in Python to asynchronously invoke the get_coauthors tool and print the result. ```python import asyncio from mcp import Client async def main(): async with Client("http://localhost:8081") as client: result = await client.invoke_tool( "get_coauthors", { "name": "Albert", "surname": "Einstein" } ) print(result) asyncio.run(main()) ``` -------------------------------- ### Start Author Profile MCP in HTTP Mode Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Starts the Author Profile MCP using HTTP transport, typically for deployment in containerized environments. Specifies port and host. ```bash # Docker environment (from Dockerfile) TRANSPORT=http PORT=8081 HOST=0.0.0.0 python server.py ``` ```text # Output: # INFO:root:Starting HTTP server on 0.0.0.0:8081 ``` -------------------------------- ### Basic Co-author Search Example Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/search.md Demonstrates how to initialize AuthorSearchEngine and retrieve co-authors for a given name and surname. Prints the count and details of the first five co-authors found. ```python import asyncio from search import AuthorSearchEngine async def main(): async with AuthorSearchEngine() as engine: coauthors = await engine.get_coauthors("Marie", "Curie") print(f"Found {len(coauthors)} co-authors") for author in coauthors[:5]: print(f" - {author['name']}: {author['collaborations']} papers") asyncio.run(main()) ``` -------------------------------- ### POST /invoke/get_coauthors Response Body Example (Error) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/endpoints.md Example of an error JSON response body when the operation is not successful. ```json { "success": false, "error": "Error message describing what went wrong", "coauthors": [] } ``` -------------------------------- ### Get Co-authors with Institution (cURL) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/MANIFEST.md Example of how to retrieve co-authors for a specific author, including their institution, using cURL. ```shell curl -X POST \ http://localhost:8000/invoke/get_coauthors \ -H 'Content-Type: application/json' \ -d '{ "name": "Alperen", "surname": "Koçyiğit", "institution": "Sabancı University" }' ``` -------------------------------- ### Python Example using requests for POST /invoke/get_coauthors Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/endpoints.md Shows how to use the Python 'requests' library to call the get_coauthors endpoint and process the response, including error handling. ```python import requests response = requests.post( 'http://localhost:8081/invoke/get_coauthors', json={ 'name': 'Marie', 'surname': 'Curie', 'institution': 'University of Paris' } ) if response.json()['success']: for coauthor in response.json()['coauthors']: print(f"{coauthor['name']}: {coauthor['collaborations']} papers") else: print(f"Error: {response.json()['error']}") ``` -------------------------------- ### Get Keywords from Google Scholar (cURL) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/MANIFEST.md Example of how to retrieve research keywords for an author from Google Scholar using cURL. ```shell curl -X POST \ http://localhost:8000/invoke/get_author_keywords \ -H 'Content-Type: application/json' \ -d '{ "name": "Alperen", "surname": "Koçyiğit", "institution": "Sabancı University" }' ``` -------------------------------- ### Start Author Profile MCP in STDIO Mode Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Launches the Author Profile MCP in its default STDIO mode. This is a minimal configuration for local testing or simple deployments. ```bash # Minimal configuration python server.py ``` ```text # Output: # INFO:root:Starting STDIO server ``` -------------------------------- ### Health Check Response Example Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/endpoints.md Example JSON response for the /health endpoint, indicating the server's operational status. ```json { "status": "healthy" } ``` -------------------------------- ### Error Response Example Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Shows the JSON format for an error response, indicating failure and providing an error message. ```json { "success": false, "error": "Description of what went wrong", "coauthors": [] } ``` -------------------------------- ### Reverse Proxy Setup (Nginx) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/MANIFEST.md Configuration snippet for setting up Nginx as a reverse proxy to the Author Profile MCP service. This is useful for production deployments. ```nginx server { listen 80; server_name your_domain.com; location / { proxy_pass http://localhost:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } ``` -------------------------------- ### Keywords from Multiple Sources Example Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/search.md Shows how to fetch author keywords, prioritizing Google Scholar and falling back to Semantic Scholar if the first source yields no results. Displays keywords from both sources. ```python import asyncio from search import AuthorSearchEngine async def main(): async with AuthorSearchEngine() as engine: # Try Google Scholar first scholar_kw = await engine.get_author_keywords_from_scholar("Albert", "Einstein") if scholar_kw: print("Scholar keywords:", scholar_kw) # Fall back to semantic scholar extraction ss_kw = await engine.get_author_keywords("Albert", "Einstein") print("Semantic Scholar keywords:", [kw['keyword'] for kw in ss_kw]) asyncio.run(main()) ``` -------------------------------- ### Make HTTP GET Request Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/search.md Makes an HTTP GET request with error handling and lazy session initialization. Returns parsed JSON on success or None on various errors. ```python async def _make_request( self, url: str, headers: Dict = None ) -> Optional[Dict] # Example: data = await engine._make_request( "https://api.semanticscholar.org/graph/v1/author/search?query=John%20Doe", headers={"Accept": "application/json"} ) if data: print(data['data']) ``` -------------------------------- ### Retrieve Keywords via HTTP Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Example using curl to send a POST request to the /invoke/get_author_keywords endpoint to retrieve keywords associated with an author. ```bash curl -X POST http://localhost:8081/invoke/get_author_keywords \ -H "Content-Type: application/json" \ -d '{ "name": "Yann", "surname": "LeCun" }' ``` -------------------------------- ### Server Tool Definitions Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Defines tools for server-side operations using the MCP framework, including getting co-authors and author keywords. ```python @mcp.tool() async def get_coauthors(name: str, surname: str, institution: Optional[str] = None, field: Optional[str] = None) -> Dict[str, Any] @mcp.tool() async def get_author_keywords(name: str, surname: str, institution: Optional[str] = None) -> Dict[str, Any] ``` -------------------------------- ### Custom Port Configuration (Docker) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/MANIFEST.md Example of how to run the Author Profile MCP Docker container on a custom port. This involves mapping a host port to the container's port. ```shell docker run -p 9000:8000 author-profile-mcp ``` -------------------------------- ### Set Logging Level via Environment Variable (Python) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Example of how to modify the logging configuration to accept a LOG_LEVEL environment variable. This is not yet implemented in the main server code. ```python # In server.py import os log_level = os.getenv("LOG_LEVEL", "INFO") logging.basicConfig(level=log_level) ``` -------------------------------- ### GET /health Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/endpoints.md Checks the health and readiness status of the server. This is a built-in endpoint provided by FastAPI. ```APIDOC ## GET /health ### Description Check server health and readiness. This endpoint is provided by FastAPI. ### Method GET ### Endpoint /health ### Response #### Success Response (200) - **status** (string) - The health status of the server, typically "healthy". #### Response Example ```json { "status": "healthy" } ``` ``` -------------------------------- ### Test Server Health Endpoint Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Uses curl to send a GET request to the /health endpoint and shows the expected JSON response. ```bash curl http://localhost:8081/health # Returns: {"status": "healthy"} ``` -------------------------------- ### _make_request Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/search.md Makes HTTP GET request with error handling and lazy session initialization. It handles various network and HTTP errors by returning None and logs them appropriately. ```APIDOC ## _make_request ### Description Makes HTTP GET request with error handling and lazy session initialization. ### Method GET ### Endpoint {url} ### Parameters #### Query Parameters - **url** (str) - Required - Full URL to request - **headers** (Dict) - Optional - HTTP headers dictionary ### Response #### Success Response (200) - **data** (Dict) - Parsed JSON response ### Response Example ```json { "data": {} } ``` ### Error Handling: - HTTP status != 200: Return None (Log Level: WARNING) - asyncio.TimeoutError: Return None (Log Level: ERROR) - aiohttp.ClientSSLError: Return None (Log Level: ERROR) - aiohttp.ClientError: Return None (Log Level: ERROR) - Unexpected exceptions: Return None (Log Level: ERROR) ``` -------------------------------- ### Retrieve Co-authors via HTTP Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Example using curl to send a POST request to the /invoke/get_coauthors endpoint to retrieve co-author information for a given author. ```bash curl -X POST http://localhost:8081/invoke/get_coauthors \ -H "Content-Type: application/json" \ -d '{ "name": "Yann", "surname": "LeCun", "institution": "NYU" }' ``` -------------------------------- ### Server Level Try-Catch Block Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/errors.md Example of a try-catch block at the server level in Python, handling exceptions during the `get_coauthors` call and returning a JSON error response. ```python try: result = await search_engine.get_coauthors(...) except Exception as e: logger.error(f"Error getting co-authors: {str(e)}") return {"success": False, "error": str(e), "coauthors": []} ``` -------------------------------- ### Normalize Author Name Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/search.md Normalizes author names by converting to lowercase and collapsing whitespace for consistent comparison. Example shows normalization of a name with extra spaces. ```python def _normalize_author_name(self, name: str) -> str # Example: normalized = engine._normalize_author_name(" John DOE ") # Returns: "john doe" ``` -------------------------------- ### Search Engine Level Try-Catch Block Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/errors.md Example of a try-catch block within the search engine in Python, handling HTTP requests and asyncio timeouts. It logs warnings for non-200 status codes and errors for timeouts. ```python try: async with self.session.get(url, headers=headers) as response: if response.status == 200: return await response.json() else: logger.warning(f"Request failed: {url} - Status: {response.status}") return None except asyncio.TimeoutError: logger.error(f"Timeout error for {url}") return None ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/README.md Creates a virtual environment for the project and activates it. Use the appropriate activation command for your operating system. ```bash python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate ``` -------------------------------- ### Project File Structure Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Overview of the project's directory structure, listing key files and their purposes. ```bash . ├── server.py # FastMCP server & tool definitions ├── search.py # AuthorSearchEngine class (900 lines) ├── requirements.txt # Python dependencies ├── Dockerfile # Container configuration ├── smithery.yaml # Smithery deployment config └── README.md # User documentation ``` -------------------------------- ### Direct AuthorSearchEngine Usage (Python Async) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/MANIFEST.md Demonstrates direct usage of the AuthorSearchEngine class asynchronously in Python. Requires importing the class and initializing it. ```python from author_profile_mcp.search import AuthorSearchEngine async def main(): async with AuthorSearchEngine() as engine: coauthors = await engine.get_coauthors("Alperen", "Koçyiğit", "Sabancı University") print(coauthors) if __name__ == "__main__": import asyncio asyncio.run(main()) ``` -------------------------------- ### AuthorSearchEngine Constructor Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/search.md Initializes a new AuthorSearchEngine instance. State includes session, cache, and rate limit tracking. Recommended to use within an async context manager. ```python class AuthorSearchEngine: def __init__(self) ``` ```python from search import AuthorSearchEngine # Create instance engine = AuthorSearchEngine() # Use in context manager (recommended) async with engine as search_engine: coauthors = await search_engine.get_coauthors("Yann", "LeCun") ``` -------------------------------- ### Docker Deployment Commands Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Commands for building and running the Docker image, including options for default settings, custom ports, and localhost binding. ```bash # Build image docker build -t authorprofile . # Run with default settings (HTTP on 0.0.0.0:8081) docker run -p 8081:8081 authorprofile # Run with custom port docker run -e PORT=3000 -p 3000:3000 authorprofile # Run with localhost binding (behind reverse proxy) docker run -e HOST=127.0.0.1 -p 8081:8081 authorprofile ``` -------------------------------- ### Initialize Rate Limiting Configuration (Python) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Sets up the initial state for API rate limiting, with call counts reset to zero and reset times set to the current time for multiple external APIs. ```python self.rate_limits = { 'semantic_scholar': {'calls': 0, 'reset_time': time.time()}, 'openalex': {'calls': 0, 'reset_time': time.time()}, 'crossref': {'calls': 0, 'reset_time': time.time()}, 'arxiv': {'calls': 0, 'reset_time': time.time()}, 'pubmed': {'calls': 0, 'reset_time': time.time()} } ``` -------------------------------- ### Run Server in STDIO Mode Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/server.md Use this snippet to run the server in STDIO mode, which is the default for local development and testing. No specific environment variables are required if this is the desired mode. ```python mcp.run() ``` -------------------------------- ### Docker Build and Run Commands Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Provides commands to build a Docker image for the application and run it, exposing port 8081. ```bash docker build -t authorprofile . docker run -p 8081:8081 authorprofile ``` -------------------------------- ### get_coauthors Tool Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Retrieves a list of co-authors for a given author from multiple academic sources. This tool can be invoked via GET requests or asynchronously. ```APIDOC ## GET /invoke/get_coauthors ### Description Retrieves co-authors for a specified author by querying various academic data sources. ### Method GET ### Endpoint /invoke/get_coauthors ### Parameters #### Query Parameters - **name** (string) - Required - The first name of the author. - **surname** (string) - Required - The last name of the author. - **institution** (string) - Optional - The author's institution. - **field** (string) - Optional - The author's field of research. ### Response #### Success Response (200) - **coauthors** (list) - A list of dictionaries, where each dictionary represents a co-author and their associated data. ### Request Example ``` GET /invoke/get_coauthors?name=Albert&surname=Einstein&field=Physics ``` ### Response Example ```json { "coauthors": [ { "name": "Max Planck", "affiliation": "University of Berlin" }, { "name": "Niels Bohr", "affiliation": "University of Copenhagen" } ] } ``` ``` -------------------------------- ### Direct Async Integration with AuthorSearchEngine Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Demonstrates how to use the AuthorSearchEngine asynchronously within an async context manager to fetch co-authors. ```python from search import AuthorSearchEngine async with AuthorSearchEngine() as engine: coauthors = await engine.get_coauthors("John", "Doe") ``` -------------------------------- ### Initialize FastMCP Server Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/server.md Initializes a FastMCP server instance for the 'authorProfile' service. The underlying FastAPI application is accessible for HTTP transport. ```python from mcp.server.fastmcp import FastMCP mcp = FastMCP("authorProfile") ``` -------------------------------- ### HTTP API with Requests Library (Python Async) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/MANIFEST.md Shows how to interact with the Author Profile MCP's HTTP API using the requests library in an asynchronous Python context. Assumes the server is running. ```python import asyncio import httpx async def get_coauthors_http(): client = httpx.AsyncClient() response = await client.post("http://localhost:8000/invoke/get_coauthors", json={ "name": "Alperen", "surname": "Koçyiğit", "institution": "Sabancı University" } ) print(response.json()) await client.aclose() if __name__ == "__main__": asyncio.run(get_coauthors_http()) ``` -------------------------------- ### Configure HTTP Client SSL and Timeout (Python) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Sets up SSL context to disable hostname checking and certificate verification, and defines a client timeout for HTTP requests. ```python # SSL Configuration ssl_context = ssl.create_default_context() ssl_context.check_hostname = False ssl_context.verify_mode = ssl.CERT_NONE # Timeout Configuration timeout = aiohttp.ClientTimeout(total=30, connect=10) ``` -------------------------------- ### Configure HTTP Host Binding (Bash) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Set the IP address or hostname for the HTTP server to bind to. '0.0.0.0' binds to all interfaces, while '127.0.0.1' binds only to localhost. ```bash # Listen on all interfaces (default) TRANSPORT=http HOST=0.0.0.0 python server.py ``` ```bash # Listen on localhost only TRANSPORT=http HOST=127.0.0.1 python server.py ``` ```bash # Listen on specific interface TRANSPORT=http HOST=192.168.1.100 python server.py ``` -------------------------------- ### List Available Tools Response Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/endpoints.md This JSON structure represents the response when listing all available tools. It includes details about each tool's name, description, and input schema. ```json { "tools": [ { "name": "get_coauthors", "description": "Get all co-authors for a given author.", "inputSchema": { "type": "object", "properties": { "name": { "type": "string", "description": "Author's first name" }, "surname": { "type": "string", "description": "Author's last name" }, "institution": { "type": ["string", "null"], "description": "Optional institution affiliation", "default": null }, "field": { "type": ["string", "null"], "description": "Optional research field", "default": null } }, "required": ["name", "surname"] } }, { "name": "get_author_keywords", "description": "Get research keywords/areas for a given author from Google Scholar.", "inputSchema": { "type": "object", "properties": { "name": { "type": "string", "description": "Author's first name" }, "surname": { "type": "string", "description": "Author's last name" }, "institution": { "type": ["string", "null"], "description": "Optional institution affiliation", "default": null } }, "required": ["name", "surname"] } } ] } ``` -------------------------------- ### AuthorSearchEngine Async Context Manager Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/search.md Enables AuthorSearchEngine to be used as an async context manager, automatically handling the creation and closing of an aiohttp.ClientSession with custom configurations for SSL and connection pooling. ```python async def __aenter__(self) -> 'AuthorSearchEngine' async def __aexit__(self, exc_type, exc_val, exc_tb) ``` ```python async with AuthorSearchEngine() as engine: # Session is created on __aenter__ result = await engine.get_coauthors("John", "Doe") # Session is automatically closed on __aexit__ ``` -------------------------------- ### Get Author Keywords Tool Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/server.md Retrieves research keywords for an author from their Google Scholar profile. Use this tool to understand an author's research interests. The search can be refined by institution. ```python @mcp.tool() async def get_author_keywords( name: str, surname: str, institution: Optional[str] = None ) -> Dict[str, Any]: ... ``` ```python import asyncio from server import get_author_keywords # Run the tool result = await get_author_keywords( name="Yann", surname="LeCun" ) # Sample response # { # "success": True, # "author": "Yann LeCun", # "institution": None, # "source": "Google Scholar", # "total_keywords": 8, # "keywords": [ # "deep learning", # "neural networks", # "convolutional networks", # "machine learning" # ] # } ``` -------------------------------- ### Kubernetes Pod Deployment Specification Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/MANIFEST.md A sample Kubernetes deployment specification for running the Author Profile MCP service as a pod. This includes basic configuration for a deployment. ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: author-profile-mcp spec: replicas: 1 selector: matchLabels: app: author-profile-mcp template: metadata: labels: app: author-profile-mcp spec: containers: - name: author-profile-mcp image: author-profile-mcp:latest ports: - containerPort: 8000 ``` -------------------------------- ### List Available Tools Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/endpoints.md Retrieves a list of all tools available for invocation through the MCP framework. Each tool includes its name, description, and input schema. ```APIDOC ## GET /tools ### Description Lists all available tools that can be invoked via the MCP framework. This endpoint provides information about each tool's purpose and the expected input parameters. ### Method GET ### Endpoint /tools ### Parameters #### Query Parameters None #### Request Body None ### Response #### Success Response (200 OK) - **tools** (array) - A list of available tools. Each tool object contains: - **name** (string) - The unique name of the tool. - **description** (string) - A brief explanation of what the tool does. - **inputSchema** (object) - The JSON schema defining the expected input parameters for the tool. #### Response Example ```json { "tools": [ { "name": "get_coauthors", "description": "Get all co-authors for a given author.", "inputSchema": { "type": "object", "properties": { "name": {"type": "string", "description": "Author's first name"}, "surname": {"type": "string", "description": "Author's last name"}, "institution": {"type": ["string", "null"], "description": "Optional institution affiliation", "default": null}, "field": {"type": ["string", "null"], "description": "Optional research field", "default": null} }, "required": ["name", "surname"] } }, { "name": "get_author_keywords", "description": "Get research keywords/areas for a given author from Google Scholar.", "inputSchema": { "type": "object", "properties": { "name": {"type": "string", "description": "Author's first name"}, "surname": {"type": "string", "description": "Author's last name"}, "institution": {"type": ["string", "null"], "description": "Optional institution affiliation", "default": null} }, "required": ["name", "surname"] } } ] } ``` **Authentication:** None required **Rate Limit:** Not rate-limited ``` -------------------------------- ### Get Coauthors from Multiple Sources Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/search.md Retrieves and aggregates co-authors by querying Semantic Scholar, OpenAlex, and Crossref in parallel. Results are cached and sorted by collaboration count. Handles errors from individual APIs gracefully. ```python async def get_coauthors( name: str, surname: str, institution: Optional[str] = None, field: Optional[str] = None ) -> List[Dict] ``` ```python async with AuthorSearchEngine() as engine: coauthors = await engine.get_coauthors( name="Marie", surname="Curie", institution="University of Paris" ) for coauthor in coauthors: print(f"{coauthor['name']}: {coauthor['collaborations']} collaborations") # Output: # Pierre Curie: 42 collaborations # Paul Langevin: 15 collaborations ``` -------------------------------- ### Smithery Deployment Command Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Command to deploy the application using Smithery based on a configuration file. ```bash smithery deploy --config smithery.yaml ``` -------------------------------- ### Get Co-authors Tool Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/server.md Retrieves co-author information for a given author, querying multiple data sources. Use this tool to explore collaboration networks. Optional parameters can refine the search by institution and research field. ```python @mcp.tool() async def get_coauthors( name: str, surname: str, institution: Optional[str] = None, field: Optional[str] = None ) -> Dict[str, Any]: ... ``` ```python import asyncio from server import get_coauthors # Run the tool result = await get_coauthors( name="Yann", surname="LeCun", institution="NYU" ) # Sample response # { # "success": True, # "author": "Yann LeCun", # "institution": "NYU", # "total_coauthors": 142, # "coauthors": [ # { # "name": "Yoshua Bengio", # "collaborations": 15, # "source": "semantic_scholar" # }, # { # "name": "Geoffrey Hinton", # "collaborations": 8, # "source": "semantic_scholar" # } # ] # } ``` -------------------------------- ### Kubernetes Deployment Command Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Command to apply a Kubernetes deployment configuration from a YAML file. ```bash kubectl apply -f k8s-deployment.yaml ``` -------------------------------- ### Monitor Cache and Rate Limits Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Python code to print the current cache size and rate limit status from the AuthorSearchEngine instance. ```python print(f"Cache size: {len(engine.cache)} entries") print(f"Rate limits: {engine.rate_limits}") ``` -------------------------------- ### Configure HTTP Port (Bash) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Set the listening port for the HTTP server. Common ports include 8081 for development and 80/443 for production. ```bash # Default port TRANSPORT=http python server.py ``` ```bash # Custom port TRANSPORT=http PORT=3000 python server.py ``` ```bash # Production setup (requires reverse proxy) TRANSPORT=http HOST=127.0.0.1 PORT=8081 python server.py ``` -------------------------------- ### Run Server in HTTP Mode with Uvicorn Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/server.md This snippet demonstrates how to run the server as an HTTP application using FastAPI and Uvicorn. Ensure the TRANSPORT environment variable is set to 'http' and configure PORT and HOST as needed. ```python app = mcp.streamable_http_app uvicorn.run(app, host=host, port=port) ``` -------------------------------- ### HTTP API Integration using Requests Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Shows how to interact with the server's HTTP API using the requests library to invoke the 'get_coauthors' endpoint. ```python import requests response = requests.post("http://localhost:8081/invoke/get_coauthors", json={"name": "Jane", "surname": "Doe"}) result = response.json() ``` -------------------------------- ### MCP Protocol Integration with Claude Client Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Illustrates invoking a tool ('get_coauthors') over the MCP protocol using the Client class within an async context. ```python from mcp import Client async with Client("http://localhost:8081") as client: result = await client.invoke_tool("get_coauthors", {"name": "Jane", "surname": "Doe"}) ``` -------------------------------- ### Configure HTTP Host Binding (Python) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Python code to retrieve the HOST environment variable for HTTP server binding, defaulting to '0.0.0.0'. ```python host = os.getenv("HOST", "0.0.0.0") uvicorn.run(app, host=host, port=port) ``` -------------------------------- ### Using AuthorSearchEngine Cache Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/search.md Illustrates the use of the AuthorSearchEngine's caching mechanism. The first call to `get_coauthors` populates the cache, while subsequent calls with the same arguments retrieve results instantly from memory. ```python async with AuthorSearchEngine() as engine: # First call queries APIs coauthors1 = await engine.get_coauthors("John", "Doe") # Second call returns cached result instantly coauthors2 = await engine.get_coauthors("John", "Doe") # Same cache key as above coauthors3 = await engine.get_coauthors("John", "Doe", "MIT") ``` -------------------------------- ### Enable Debug Logging Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/errors.md Sets the log level to DEBUG for detailed logging output when running the server. This is useful for debugging. ```bash LOG_LEVEL=DEBUG python server.py ``` -------------------------------- ### Retrieve Co-authors using Python Async Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Demonstrates how to use the AuthorSearchEngine asynchronously in Python to fetch co-author data. Requires the 'search' module. ```python import asyncio from search import AuthorSearchEngine async def main(): async with AuthorSearchEngine() as engine: coauthors = await engine.get_coauthors( "Albert", "Einstein", institution="Princeton" ) print(f"Found {len(coauthors)} co-authors") asyncio.run(main()) ``` -------------------------------- ### Set Server Transport Mode (Bash) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Configure the communication protocol for the MCP server. Use 'stdio' for local development and testing, or 'http' for remote deployment and API access. ```bash # STDIO mode (default) python server.py ``` ```bash # HTTP mode TRANSPORT=http python server.py ``` -------------------------------- ### Dockerfile for Author Profile MCP Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Defines the Docker image for the Author Profile MCP. It sets up the Python environment, configures HTTP transport, and exposes the default port. ```dockerfile # Base image FROM python:3.11-slim # HTTP transport enabled ENV TRANSPORT=http ENV PORT=8081 ENV HOST=0.0.0.0 # Port exposure EXPOSE 8081 ``` -------------------------------- ### Smithery Configuration for Docker Deployment Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Configures Smithery to use Docker for building and running the application. It specifies the Dockerfile and expects HTTP transport. ```yaml runtime: "container" build: dockerfile: "Dockerfile" dockerBuildPath: "." startCommand: type: "http" ``` -------------------------------- ### Set Server Transport Mode (Python) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Implementation of transport mode selection based on the TRANSPORT environment variable. Defaults to 'stdio' if not set. ```python transport = os.getenv("TRANSPORT", "stdio") if transport == "http": # Run HTTP server app = mcp.streamable_http_app uvicorn.run(app, host=host, port=port) else: # Run STDIO mode mcp.run() ``` -------------------------------- ### Production Environment Variables Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/endpoints.md Configures essential environment variables for running the API in a production environment, including transport mode, port, host, and logging level. ```bash TRANSPORT=http # Enable HTTP mode PORT=8080 # Custom port HOST=127.0.0.1 # Restrict to localhost LOG_LEVEL=INFO # Logging level ``` -------------------------------- ### Optional Parameter Annotation Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/types.md Illustrates how to annotate optional parameters that default to None, using Optional[Type]. ```python parameter: Optional[str] = None ``` -------------------------------- ### Configure Python Logging Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/server.md This snippet shows how to configure Python's built-in logging module to log activities at the INFO level. All messages will be directed to standard output or standard error. ```python import logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) ``` -------------------------------- ### Enable Debug Logging in Server Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Configuration snippet for enabling debug logging in the Python server by modifying the logging basicConfig level. ```bash # Modify server.py logging.basicConfig(level=logging.DEBUG) ``` -------------------------------- ### Configure aiohttp TCPConnector Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Sets up a TCP connector for aiohttp with custom limits and cleanup settings. Useful for managing concurrent connections to external APIs. ```python connector = aiohttp.TCPConnector( ssl=ssl_context, limit=100, limit_per_host=10, enable_cleanup_closed=True ) ``` -------------------------------- ### Generate Cache Key Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/search.md Generates an MD5-based cache key from a variable list of arguments. The key is a 32-character hexadecimal string. ```python def _get_cache_key(self, *args) -> str ``` ```python key = engine._get_cache_key('coauthors', 'John', 'Doe', 'MIT') # Returns: '5d41402abc4b2a76b9719d911017c592' ``` -------------------------------- ### Nginx Reverse Proxy Configuration Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/endpoints.md Sets up an Nginx reverse proxy to route incoming requests to the Author Profile API server running on a specified port. ```nginx upstream authorprofile { server localhost:8081; } server { listen 80; server_name api.example.com; location / { proxy_pass http://authorprofile; proxy_set_header Content-Type application/json; } } ``` -------------------------------- ### HTTPConfig Structure Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/types.md Configuration for the HTTP transport mode, specifying the server host and port. ```python { "transport": str, # Always "http" "host": str, # Server binding address (default: "0.0.0.0") "port": int # Server port number (default: 8081) } ``` -------------------------------- ### _search_arxiv Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/search.md Queries the arXiv API for preprints by author. Note: Returns a simplified structure due to XML parsing limitations. ```APIDOC ## _search_arxiv ### Description Queries arXiv API for preprints by author. Note: Returns simplified structure due to XML parsing. ### Method GET ### Endpoint /search ### Parameters #### Query Parameters - **name** (str) - Required - Author's first name - **surname** (str) - Required - Author's last name ### Response #### Success Response (200) - **results** (List[Dict]) - Simplified list of preprints by the author ### Rate Limit 30 calls per hour ### Maximum Results 50 per query ### Note This is a simplified implementation. Full XML parsing is not yet implemented. ``` -------------------------------- ### Search arXiv API Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/api-reference/search.md Queries the arXiv API for preprints by author, returning a simplified structure due to XML parsing. Limited to 30 calls per hour with a maximum of 50 results per query. ```python async def _search_arxiv( self, name: str, surname: str ) -> List[Dict] # Example: results = await engine._search_arxiv("Albert", "Einstein") ``` -------------------------------- ### Increase Timeout Settings in search.py Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Adjusts the aiohttp ClientTimeout settings to increase the total request duration and connection timeout, beneficial for slow network conditions. ```python timeout = aiohttp.ClientTimeout( total=60, # Increased from 30 connect=20 # Increased from 10 ) ``` -------------------------------- ### View Cache Contents Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/errors.md Displays the contents of the cache, which is keyed by the MD5 hash of the arguments used in the calls. This is useful for debugging caching mechanisms. ```python print(engine.cache) # Keyed by MD5 hash of arguments ``` -------------------------------- ### Configure HTTP Port (Python) Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Python code to retrieve the PORT environment variable for the HTTP server, defaulting to 8081. ```python port = int(os.getenv("PORT", 8081)) uvicorn.run(app, host=host, port=port) ``` -------------------------------- ### AuthorSearchEngine Class Definition Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/README.md Defines the asynchronous context manager and public API methods for searching author information. ```python class AuthorSearchEngine: # Async context manager for session management async def __aenter__(self) -> AuthorSearchEngine async def __aexit__(exc_type, exc_val, exc_tb) # Public API async def get_coauthors(name, surname, institution?, field?) -> List[Dict] async def get_author_keywords(name, surname, institution?) -> List[Dict] async def get_author_keywords_from_scholar(name, surname, institution?) -> List[str] ``` -------------------------------- ### Collection Return Type Annotation - Dict String to Int Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/types.md Shows the type hint for a method that returns a dictionary with string keys and integer values. ```python def method() -> Dict[str, int]: # Dictionary with string keys, int values ``` -------------------------------- ### Kubernetes Pod Configuration Source: https://github.com/alperenkocyigit/authorprofilemcp/blob/main/_autodocs/configuration.md Defines a Kubernetes Pod to run the Author Profile MCP. It specifies the container image, environment variables for transport, port, and host, and exposes the container port. ```yaml apiVersion: v1 kind: Pod metadata: name: authorprofile spec: containers: - name: authorprofile image: authorprofile:latest env: - name: TRANSPORT value: "http" - name: PORT value: "8081" - name: HOST value: "0.0.0.0" ports: - containerPort: 8081 ```