Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/openapi-mcp-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
82 changes: 82 additions & 0 deletions src/openapi-mcp-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# OpenAPI MCP Server

This server acts as a bridge 🌉, dynamically generating **Model Context Protocol (MCP)** tools from **OpenAPI specifications**. This allows Large Language Models (LLMs) to seamlessly interact with your APIs.

---
## ✨ Features

* ⚡ **Dynamic Tool Generation**: Automatically creates MCP tools from any OpenAPI endpoint for LLM interaction.
* 📡 **Transport Options**: Natively supports `stdio` transport for communication.
* ⚙️ **Flexible Configuration**: Easily configure the server using command-line arguments or environment variables.
* 📚 **OpenAPI & Swagger Support**: Compatible with OpenAPI 3.x and Swagger specs in both JSON and YAML formats.
* 🔑 **Authentication Support**: Handles multiple authentication methods, including Basic, Bearer Token, API Key, and custom headers.

---
## 🚀 Getting Started

### Prerequisites

* **Java 21**: Make sure the JDK is installed and your `JAVA_HOME` environment variable is set correctly.
* **Maven 3.x**: Required for building the project and managing its dependencies.
* **Valid OpenAPI Specification**: You'll need a JSON or YAML file describing the API you want to connect to.

### Installation & Build

1. **Clone the repository** and navigate to the project directory.
2. **Build the project** into a runnable JAR file using Maven. This is the only step needed before configuring your client.
```bash
mvn clean package -P release
```

---
## 🔧 Configuration

The MCP OpenAPI Server can be configured via **command-line arguments** or **environment variables**.

| CLI Argument | Environment Variable | Description | Example |
| :--- | :--- | :--- | :--- |
| `--api-name` | `API_NAME` | Friendly name for the API (used in logs/debug). | `PetStore` |
| `--api-base-url` | `API_BASE_URL` | Base URL of the API. | `https://api.example.com/v1` |
| `--api-spec` | `API_SPEC` | Path or URL to the OpenAPI specification. | `/configs/openapi.yaml` |
| `--auth-type` | `AUTH_TYPE` | Authentication type (`BASIC`, `BEARER`, `API_KEY`). | `BEARER` |
| `--auth-token` | `AUTH_TOKEN` | Token for Bearer authentication. | `eyJhbGciOiJIUzI1NiIsInR5cCI6...` |
| `--auth-username` | `AUTH_USERNAME` | Username for Basic authentication. | `adminUser` |
| `--auth-password` | `AUTH_PASSWORD` | Password for Basic authentication. | `P@ssw0rd!` |
| `--auth-api-key` | `AUTH_API_KEY` | API key value for `API_KEY` authentication. | `12345-abcdef-67890` |
| `--auth-api-key-name` | `API_API_KEY_NAME` | Name of the API key parameter. | `X-API-KEY` |
| `--auth-api-key-in` | `API_API_KEY_IN` | Location of API key (`header` or `query`). | `header` |
| `--auth-custom-headers` | `AUTH_CUSTOM_HEADERS` | JSON string of custom authentication headers. | `{"X-Tenant-ID": "acme"}` |
| `--http-version` | `API_HTTP_VERSION` | HTTP version (`HTTP_1_1`, `HTTP_2`). | `HTTP_2` |
| `--http-redirect` | `API_HTTP_REDIRECT` | Redirect policy (`NEVER`, `NORMAL`, `ALWAYS`). | `NORMAL` |
| `--proxy-host` | `API_HTTP_PROXY_HOST` | Proxy host if needed. | `proxy.example.com` |
| `--proxy-port` | `API_HTTP_PROXY_PORT` | Proxy port number. | `8080` |
| `--tool-overrides` | `MCP_TOOL_OVERRIDES` | JSON string of tool override configuration. | `{ "includeOnly": ["listUsers", "getUser"], "exclude": ["deleteUser"], "tools": [ { "name": "listUsers", "description": "Custom listUsers tool with pagination" ] }` |

---
## 🔌 Integrating with an MCP Client

The MCP client launches this server as a short-lived process whenever API interaction is needed. Your client configuration must specify the command to execute the .jar file along with its arguments.
#### Example: Client JSON Configuration

Here's how you might configure a client (like VS Code's Cline) to invoke this server, passing the required arguments.

```json
{
"mcpServers": {
"my-api-server": {
"command": "java",
"args": [
"-jar",
"/path/to/your/project/target/openapi-mcp-server-1.0.jar",
"--api-spec",
"[https://api.example.com/openapi.json](https://api.example.com/openapi.json)",
"--api-base-url",
"[https://api.example.com](https://api.example.com)"
],
"env": {
"AUTH_TYPE": "BEARER",
"AUTH_TOKEN": "your-secret-token-here"
}
}
}
}
139 changes: 139 additions & 0 deletions src/openapi-mcp-server/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.oracle.mcp.openapi</groupId>
<artifactId>openapi-mcp-server</artifactId>
<name>Open API MCP Server</name>
<description>
The OpenAPI MCP Server is a Java-based implementation of an MCP (Model Context Protocol) server that works with OpenAPI specifications. It fetches OpenAPI schemas, converts them into MCP tools, and registers these tools with the MCP server.
</description>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<developers>
<developer>
<name>Joby Mathews</name>
<email>joby.mathews@oracle.com</email>
<organization>Oracle</organization>
<organizationUrl>https://www.oracle.com</organizationUrl>
<url>https://github.com/jobyywilson</url>
<roles>
<role>Developer</role>
</roles>
</developer>
</developers>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.boot.version>3.2.5</spring.boot.version>
<surefire.version>3.2.5</surefire.version>
<jar.finalName>${project.artifactId}-${project.version}</jar.finalName>
</properties>

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring.boot.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.17.0</version>
</dependency>

<!-- MCP SDK -->
<dependency>
<groupId>io.modelcontextprotocol.sdk</groupId>
<artifactId>mcp</artifactId>
<version>0.11.1</version>
</dependency>

<dependency>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser</artifactId>
<version>2.1.22</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.13</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.18</version>
</dependency>

<dependency>
<groupId>io.modelcontextprotocol.sdk</groupId>
<artifactId>mcp-test</artifactId>
<version>0.11.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>3.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>${jar.finalName}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>release</id>
<properties>
<jar.finalName>${project.artifactId}-1.0</jar.finalName>
</properties>
</profile>
</profiles>

</project>

Loading