add_api
Add a new API configuration by specifying a name, base URL, and optional details such as description or authentication headers. Simplify API integration and management within the MCP server.
Instructions
Add a new API configuration with name, URL and optional description
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | No | Optional description | |
| headers | No | Optional HTTP headers for authentication (e.g., {'Authorization': 'Bearer token', 'X-API-Key': 'key'}) | |
| name | Yes | Short name for the API | |
| url | Yes | Base URL of the FastAPI service |
Implementation Reference
- The handle_call method of AddApiTool that executes the tool logic by invoking config_manager.add_api with parsed arguments.async def handle_call(self, arguments: Dict[str, Any]) -> List[TextContent]: try: result = await self.config_manager.add_api( arguments["name"], arguments["url"], arguments.get("description"), arguments.get("headers"), ) return self._create_text_response(result) except Exception as e: return self._create_error_response(e)
- Static method defining the JSON schema for add_api tool inputs, used in tool definition.def create_add_api_input_schema() -> Dict[str, Any]: """Create input schema for adding API.""" return { "type": "object", "properties": { "name": {"type": "string", "description": "Short name for the API"}, "url": { "type": "string", "description": "Base URL of the FastAPI service", }, "description": { "type": "string", "description": "Optional description", }, "headers": { "type": "object", "description": "Optional HTTP headers for authentication (e.g., {'Authorization': 'Bearer token', 'X-API-Key': 'key'})", "additionalProperties": {"type": "string"}, }, }, "required": ["name", "url"], }
- openapi_mcp_proxy/services/tool_registry.py:39-56 (registration)Instantiates AddApiTool and registers it in the tool registry dictionary during _register_tools.tools = [ # API Management Tools AddApiTool(self.config_manager), ListSavedApisTool(self.config_manager), RemoveApiTool(self.config_manager), # API Exploration Tools GetApiInfoTool(self.config_manager, self.explorer), ListEndpointsTool(self.config_manager, self.explorer), SearchEndpointsTool(self.config_manager, self.explorer), GetEndpointDetailsTool(self.config_manager, self.explorer), ListModelsTool(self.config_manager, self.explorer), GetModelSchemaTool(self.config_manager, self.explorer), ] for tool in tools: self._tools[tool.name] = tool logger.debug(f"Registered tool: {tool.name}")
- Core method called by the tool handler to add the API config, validate, store, and persist to file.async def add_api( self, name: str, url: str, description: Optional[str] = None, headers: Optional[Dict[str, str]] = None, ) -> str: """Add a new API configuration.""" try: api_config = ApiConfig( name=name, url=url, description=description, headers=headers or {} ) self._storage.add_api(api_config) await self.save_config() logger.info(f"Added API configuration: {name}") return f"Added API '{name}' with URL {url}" except ValidationError as e: raise ValueError(f"Invalid URL or configuration: {e}")
- Storage method that actually stores the ApiConfig in the in-memory dictionary.def add_api(self, config: ApiConfig) -> None: """Add an API configuration.""" self.apis[config.name] = config