OpenAPI to MCP Generator (openapi-mcp-generator)
https://github.com/harsha-iiiv/openapi-mcp-generator
http://localhost:8181/ords/apexdev/open-api-catalog/hr/
RESTサービスをOAuth2で保護した上で、MCPサーバーとしてアクセスできるようにします。APEXのワークスペース・スキーマに接続し、以下のスクリプトを実行することでRESTサービスをOAuth2で保護します。
SQL> @protect-sample-hr-emp-module.sql
Role HR Example Role has already created.
Privilege oracle.example.hr has already created.
OAuth client mcp_client has already created.
client_id: Ai3VSXvO9k5qI2cLWg-H-g..
client_secret: y9_uZIaNT1cqvOcV8lxSEw..
Role HR Example Role has granted to OAuth user mcp_client.
PL/SQLプロシージャが正常に完了しました。
SQL>
run.shというファイルを作成し、その中で上記のclient_idを環境変数OAUTH_CLIENT_ID_OAUTH2、client_secretをOAUTH_CLIENT_SECRET_OAUTH2に設定します。末尾の .. (ピリオド2つ)も値の一部なので、忘れずに値に含めます。
#!/bin/sh
export OAUTH_CLIENT_ID_OAUTH2=[client_idの値]
export OAUTH_CLIENT_SECRET_OAUTH2=[client_secretの値]
# Workaround for OAuth2 client credentials authentication.
export OAUTH_CLIENT_ID_SCHEMENAME=${OAUTH_CLIENT_ID_OAUTH2}
export OAUTH_CLIENT_SECRET_SCHEMENAME=${OAUTH_CLIENT_SECRET_OAUTH2}
node /Users/_____/Documents/hr-emp-mcp/server/build/index.js
hr-emp-mcp % chmod 755 run.sh
hr-emp-mcp %
npm install -g openapi-mcp-generator
hr-emp-mcp % npm install -g openapi-mcp-generator
changed 107 packages in 4s
22 packages are looking for funding
run `npm fund` for details
hr-emp-mcp %
RESTモジュールoracle.example.hrを呼び出すMCPサーバーを生成します。今回の作業ではSTDIOのサーバーを生成しています。この他にStreamableHTTPにも対応しているようです。
hr-emp-mcp % openapi-mcp-generator --input http://localhost:8181/ords/apexdev/open-api-catalog/hr/ --output ./server
Parsing OpenAPI spec: http://localhost:8181/ords/apexdev/open-api-catalog/hr/
OpenAPI spec parsed successfully.
Generating server code...
Generating package.json...
Generating tsconfig.json...
Generating .gitignore...
Generating ESLint config...
Generating Prettier config...
Generating Jest config...
Generating .env.example file...
Generating OAuth2 documentation...
Creating project directory structure at: ./server
-> Created server/src/index.ts
-> Created server/package.json
-> Created server/tsconfig.json
-> Created server/.gitignore
-> Created server/.eslintrc.json
-> Created server/.prettierrc
-> Created server/jest.config.js
-> Created server/.env.example
-> Created server/docs/oauth2-configuration.md
---
MCP server project 'ords-generated-api-for-oracle-example-hr' successfully generated at: ./server
Next steps:
1. Navigate to the directory: cd ./server
2. Install dependencies: npm install
3. Build the TypeScript code: npm run build
4. Run the server: npm start
(This runs the built JavaScript code in build/index.js)
---
ynakakoshi@Ns-Macbook hr-emp-mcp %
Next stepsに書かれている作業を行います。
hr-emp-mcp % cd ./server
server % npm install
added 105 packages, and audited 106 packages in 3s
22 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
server % npm run build
> ords-generated-api-for-oracle-example-hr@1.0.0 build
> tsc && chmod 755 build/index.js
server %
serverの下にbuild/index.jsが作成されます。このファイルがrun.sh内のnodeコマンドで実行されるように、run.shの記述を変更します。
#!/bin/sh
export OAUTH_CLIENT_ID_OAUTH2=Ai3VSXvO9k5qI2cLWg-H-g..
export OAUTH_CLIENT_SECRET_OAUTH2=7o5NFqrDlri9d6GQEDTBGw..
# workaround for OAuth2 client credentials authentication.
export OAUTH_CLIENT_ID_SCHEMENAME=${OAUTH_CLIENT_ID_OAUTH2}
export OAUTH_CLIENT_SECRET_SCHEMENAME=${OAUTH_CLIENT_SECRET_OAUTH2}
node /[build/index.jsを指すパス]/hr-emp-mcp/server/build/index.js