search_api_docs
Search saved API documentation by keyword to find relevant APIs for Yaizu City's smart city services and open data access.
Instructions
保存済みのAPIドキュメントから特定のキーワードでAPIを検索します。
Args: keyword: 検索キーワード(API名、説明、カテゴリで検索)
Returns: str: 検索結果
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| keyword | Yes |
Implementation Reference
- mcp/server.py:273-311 (handler)Main handler function for the 'search_api_docs' tool, decorated with @mcp.tool() for automatic registration and schema inference. It delegates search to doc_manager.search_apis and formats the results as markdown.@mcp.tool() async def search_api_docs(keyword: str) -> str: """ 保存済みのAPIドキュメントから特定のキーワードでAPIを検索します。 Args: keyword: 検索キーワード(API名、説明、カテゴリで検索) Returns: str: 検索結果 """ try: results = doc_manager.search_apis(keyword) if not results: return f"「{keyword}」に一致するAPIが見つかりませんでした。" output = f"# 検索結果: 「{keyword}」\n\n" output += f"**{len(results)}件** のAPIが見つかりました:\n\n" for i, result in enumerate(results, 1): api = result['api'] output += f"## {i}. {api.get('name', '名称不明')}\n" output += f"- **説明**: {api.get('description', '説明なし')}\n" output += f"- **カテゴリ**: {api.get('category', '未分類')}\n" output += f"- **防災関連**: {'はい' if api.get('is_disaster_related') else 'いいえ'}\n" output += f"- **ソースファイル**: {result['source_file']}.json\n" if api.get('endpoints'): output += f"- **エンドポイント**: {', '.join(api['endpoints'][:3])}\n" output += "\n" return output except Exception as e: logger.error(f"検索エラー: {e}") return f"❌ 検索中にエラーが発生しました: {str(e)}"
- mcp/server.py:97-120 (helper)Core search logic in APIDocumentManager class. Scans all available API JSON files, searches within 'apis' arrays for matching keyword in name, description, or category, and returns list of matches with source file info.def search_apis(self, keyword: str) -> List[Dict[str, Any]]: """キーワードでAPIを検索""" results = [] # すべてのドキュメントを検索 for doc_file in self.list_available_docs(): doc = self.load_api_docs(doc_file) if not doc: continue # APIs配列がある場合 if 'apis' in doc: for api in doc['apis']: # 名前と説明で検索 if (keyword.lower() in api.get('name', '').lower() or keyword.lower() in api.get('description', '').lower() or keyword.lower() in api.get('category', '').lower()): results.append({ 'source_file': doc_file, 'api': api }) return results
- mcp/server.py:273-273 (registration)The @mcp.tool() decorator registers the search_api_docs function as an MCP tool, with schema automatically derived from type annotations and docstring.@mcp.tool()
- mcp/server.py:274-283 (schema)Type hints (keyword: str -> str) and docstring provide the input/output schema for the tool.async def search_api_docs(keyword: str) -> str: """ 保存済みのAPIドキュメントから特定のキーワードでAPIを検索します。 Args: keyword: 検索キーワード(API名、説明、カテゴリで検索) Returns: str: 検索結果 """