mcp-context-forge icon indicating copy to clipboard operation
mcp-context-forge copied to clipboard

[FEATURE][UI-REWRITE]: One-click schema generation from OpenAPI in Create REST tool form

Open a-effort opened this issue 6 months ago • 8 comments

Type of Feature

  • [x] New feature or capability

Background

The backend already exposes POST /admin/tools/generate-schemas-from-openapi (mcpgateway/admin.py:11799), which:

  1. Accepts a tool url, request_type, and optional openapi_url
  2. Fetches the OpenAPI 3.x spec (defaulting to {scheme}://{host}/openapi.json)
  3. Extracts input_schema and output_schema for the requested path + method (resolving $refs in components.schemas)
  4. Returns both schemas plus the spec_url that was used

The endpoint requires tools.create permission (no admin bypass) and has SSRF protection built into mcpgateway/services/openapi_service.py.

No UI surface currently exists for this feature. The legacy admin.html doesn't expose it either, so this would be the first user-facing entry point for an otherwise-unused backend capability.

Proposal

Add a "Generate from OpenAPI" button option as a default in the Create REST Tool form. Users will continue to be able to add schemas manually, if preferred / necessary.

UX

Design

  1. Button: Disabled until url and request_type are filled (both are required by the backend endpoint).
  2. On click: call the endpoint, show a loading state on the button (the request can take up to 10s).
  3. On success:
    • Pretty-print the returned input_schema and output_schema JSON into the corresponding fields
    • Show a small caption: Generated from {spec_url} (the endpoint returns this)
  4. On failure: map the typed error responses to clear messages:
    • 400 with SSRF-related message → "URL not reachable from the gateway (blocked by SSRF protection)"
    • 404 → "The path {path} with method {method} is not in the OpenAPI spec"
    • 502 → "Couldn't fetch the OpenAPI spec — check that the URL is correct and reachable"
    • 500 → generic fallback
  5. Don't overwrite silently: if either schema field is already non-empty, ask the user to confirm before replacing.
  6. Include the manual ways to add an input and optional output schemas that the user could use if they prefer / can't use the default method of generating the schema from /admin/tools/generate-schemas-from-openapi

API client work

Extend client/src/api/tools.ts (created by the prerequisite issue) with:

async function generateSchemasFromOpenapi(input: {
  url: string;
  request_type: string;
  openapi_url?: string;
}): Promise<{
  message: string;
  success: boolean;
  input_schema: object | null;
  output_schema: object | null;
  spec_url: string;
}>;

Out of scope

  • Bulk import of multiple endpoints from a single OpenAPI spec: the backend only extracts one path+method per call. A multi-endpoint flow would be a separate feature.
  • Support for Swagger 2.0 specs the resolver doesn't currently handle, or YAML specs (backend uses orjson.loads).
  • Inferring name, description, tags from the OpenAPI operationId / summary / tags. This could be a nice follow-up but adds complexity.

Dependencies

  • Blocked by: #4860 ([UI-REWRITE]: Create REST tool)

References

  • Endpoint: mcpgateway/admin.py:11799 (POST /admin/tools/generate-schemas-from-openapi)
  • Service: mcpgateway/services/openapi_service.py:162 (fetch_and_extract_schemas)
  • Backend tests: tests/unit/mcpgateway/test_admin_openapi.py
  • Parent epic: #4093

a-effort avatar May 21 '26 23:05 a-effort

Hi @a-effort ! 👋

I'd like to work on this issue.

I've reviewed the scope, the servers.ts pattern, and issue #4175 for reference. I'm comfortable with TypeScript and React.

A few quick questions before I start:

  1. Which branch should I base this on? (ui-rewrite?)
  2. Any specific component library being used in the rewrite?
  3. Should I wait for triage to be resolved before opening a PR?

Happy to pick this up if it's still available!

prince3235 avatar May 24 '26 04:05 prince3235

This should be implemented after creating a new API endpoint described in https://github.com/IBM/mcp-context-forge/issues/5142

marekdano avatar Jun 12 '26 15:06 marekdano

Thanks for the clarification!

I'll keep an eye on #5142 and start working on this once the API endpoint is available.

prince3235 avatar Jun 12 '26 15:06 prince3235

https://github.com/IBM/mcp-context-forge/issues/5142 is closed. The API endpoint is in main now.

marekdano avatar Jun 26 '26 16:06 marekdano

@prince3235 - Do you still want to work on this issue?

marekdano avatar Jun 28 '26 20:06 marekdano

Yess a i am still working on this issue. It's little bit complicated But I handle it...

prince3235 avatar Jun 29 '26 02:06 prince3235

@prince3235 - not sure if you're working on this issue. But we had to put down the PR 5604 for this issue.

marekdano avatar Jul 13 '26 12:07 marekdano

Done!

marekdano avatar Jul 13 '26 15:07 marekdano