call_github_graphql
Execute GraphQL queries to retrieve data from GitHub repositories, users, and projects through the GitHub GraphQL API.
Instructions
A tool to execute GitHub GraphQL API queries. Before using, it's recommended to check the documentation first, and include ID fields in your queries for easier follow-up operations Args: graphql: The GraphQL query Returns: str: Execution result
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| graphql | Yes |
Implementation Reference
- github_graphql_api_mcp_server.py:108-135 (handler)The handler function for the 'call_github_graphql' tool. It executes a GraphQL query against GitHub's API using the requests library, handles authentication with a Bearer token from GITHUB_TOKEN environment variable, parses the JSON response, and returns it as a formatted string or an error message.@mcp.tool() def call_github_graphql(graphql: str) -> str: """A tool to execute GitHub GraphQL API queries. Before using, it's recommended to check the documentation first, and include ID fields in your queries for easier follow-up operations Args: graphql: The GraphQL query Returns: str: Execution result """ try: # Set request headers including authorization headers = { "Content-Type": "application/json", "Accept": "application/json", } if GITHUB_TOKEN: headers["Authorization"] = f"Bearer {GITHUB_TOKEN}" # Send POST request response = requests.post(GITHUB_API_URL, headers=headers, json={'query': graphql}) # Check response status if response.status_code == 200: # MCP tool output is expected to be a string; serialize JSON response. return json.dumps(response.json(), ensure_ascii=False) else: raise Exception(f"request failed: {response.status_code} - {response.text}") except Exception as e: return f"{e}."