retrieve_knowledge
Query DevBrain to extract relevant developer knowledge, articles, and resources. Use tags like 'ios' or 'react-native' to refine search results and access title, description, and URLs for further reading.
Instructions
Queries DevBrain (aka developers brain` system) and returns relevant information.
Args:
query: The question or ask to query for knowledge.
tags: Optional comma-separated list of tags (keywords) to filter or ground the search. (e.g.: ios, ios,SwiftUI, react-native, web, web,react, fullstack,react-native,flutter). Do not provide more than 3 words.
Returns: str: Helpful knowledge and context information from DevBrain (articles include title, short description and a URL to the full article to read it later).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| tags | No |
Input Schema (JSON Schema)
Implementation Reference
- src/mcp_server/server.py:32-61 (handler)The core handler function for the 'retrieve_knowledge' tool. It validates the API token, constructs a POST request to the DevBrain API with the query and optional tags, and returns the response text or an error message.def retrieve_knowledge(query: str, tags: str | None = None) -> str: """Queries DevBrain (aka `developer`s brain` system) and returns relevant information. Args: query: The question or ask to query for knowledge. tags: Optional comma-separated list of tags (keywords) to filter or ground the search. (e.g.: `ios`, `ios,SwiftUI`, `react-native`, `web`, `web,react`, `fullstack,react-native,flutter`). Do not provide more than 3 words. Returns: str: Helpful knowledge and context information from DevBrain (articles include title, short description and a URL to the full article to read it later). """ token_error = _enforce_token() if token_error: return token_error url = f"{api_host_base}/newsletter/find" headers = { "authorization": f"Bearer {_token}", "content-type": "application/json", } data = {"q": query} if tags: data["tags"] = tags try: response = requests.post(url, headers=headers, json=data) response.raise_for_status() # Raise an HTTPError for bad responses (4xx or 5xx) return response.text except requests.exceptions.RequestException: return "No related knowledge at this time for this search query. API error occurred - DevBrain knowledge base service is temporarily unavailable."
- src/mcp_server/server.py:31-31 (registration)The @mcp_server.tool decorator registers the retrieve_knowledge function as an MCP tool.@mcp_server.tool
- src/mcp_server/server.py:22-28 (helper)Helper function used by retrieve_knowledge to ensure the API token is set, retrieving it from environment if necessary.def _enforce_token() -> str | None: global _token if _token is None: _token = os.getenv("API_TOKEN") if _token is None: return "Token not set. You need to set `API_TOKEN` environment variable." return None
- src/mcp_server/server.py:32-41 (schema)The function signature and docstring define the input schema (query: str required, tags: str|None optional) and output (str), used by FastMCP for tool schema.def retrieve_knowledge(query: str, tags: str | None = None) -> str: """Queries DevBrain (aka `developer`s brain` system) and returns relevant information. Args: query: The question or ask to query for knowledge. tags: Optional comma-separated list of tags (keywords) to filter or ground the search. (e.g.: `ios`, `ios,SwiftUI`, `react-native`, `web`, `web,react`, `fullstack,react-native,flutter`). Do not provide more than 3 words. Returns: str: Helpful knowledge and context information from DevBrain (articles include title, short description and a URL to the full article to read it later). """