Skip to content

Commit b0ac2e4

Browse files
authored
Merge pull request #14 from h2oai/mn/custom-openapi-spec
Add option to specify custom endpoint spec file
2 parents fa5a309 + 8e6f97f commit b0ac2e4

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ make install
3939
- `basic` - A mininal set of endpoints for chatting with collections and ingesting new documents.
4040
- `custom` - A set of endpoints defined by the user. If chossen, the `H2OGPTE_CUSTOM_ENDPOINT_SET_FILE` variable must be set.
4141
- **H2OGPTE_CUSTOM_ENDPOINT_SET_FILE** - A path to file with the list of REST API endpoints. Each endpoint name must be an a separate line. The name of the endpoint is the `operationId` attribute in REST API spec file (e.g.: [https://h2ogpte.genai.h2o.ai/api-spec.yaml](https://h2ogpte.genai.h2o.ai/api-spec.yaml))
42+
- **H2OGPTE_CUSTOM_ENDPOINT_SPEC_FILE** - A path to OpenAPI spec file in YAML format describing REST API of the H2OGPTe server. If not specified, the file is obtained from the H2OGPTe server itself. This environement variable should be used only for debugging purposes.
4243

4344
### Example Configuration
4445
An example MCP server configuration for MCP clients. E.g.: Cursor, Claude Desktop

src/h2ogpte_mcp_server/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.1.4-dev"
1+
__version__ = "0.1.4"
22

33
import asyncio
44
from .server import start_server

src/h2ogpte_mcp_server/server.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ async def start_server():
1212
mux_service_url = settings.server_url
1313

1414
# Load your OpenAPI spec
15-
client = httpx.AsyncClient(base_url=f"{mux_service_url}")
16-
response = await client.get("/api-spec.yaml")
17-
yaml_spec = response.content
18-
openapi_spec = yaml.load(yaml_spec, Loader=yaml.CLoader)
15+
openapi_spec = await load_openapi_spec(mux_service_url)
1916

2017
# Create an HTTP client for your API
2118
headers = {"Authorization": f"Bearer {settings.api_key}"}
@@ -50,6 +47,17 @@ async def start_server():
5047

5148
await mcp.run_async()
5249

50+
async def load_openapi_spec(mux_service_url):
51+
if settings.custom_openapi_spec_file:
52+
with open(settings.custom_openapi_spec_file, "r") as f:
53+
custom_openapi_spec = yaml.load(f, Loader=yaml.CLoader)
54+
return custom_openapi_spec
55+
else:
56+
client = httpx.AsyncClient(base_url=f"{mux_service_url}")
57+
response = await client.get("/api-spec.yaml")
58+
yaml_spec = response.content
59+
openapi_spec = yaml.load(yaml_spec, Loader=yaml.CLoader)
60+
return openapi_spec
5361

5462
def _patched_convert_to_parameter_location(self, param_in: "ParameterLocation") -> str:
5563
return param_in.value

src/h2ogpte_mcp_server/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Settings(BaseSettings):
1515
all_endpoints_as_tools: bool = Field(True)
1616
endpoint_set: EndpointSet = Field(EndpointSet.ALL_WITHOUT_ASYNC_INGEST, case_sensitive=False)
1717
custom_endpoint_set_file: Optional[str] = Field(None)
18+
custom_openapi_spec_file: Optional[str] = Field(None)
1819

1920
settings = Settings(_env_prefix="H2OGPTE_")
2021
basic_endpoints = [

0 commit comments

Comments
 (0)