Skip to content
Merged
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
1 change: 1 addition & 0 deletions helpers/exclusion_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,4 @@
./examples/mcptoolbox-bq-claude-slack-agent
./tools/mosaic-rag-ai
./examples/creative-studio
./tools/oas-mcp-tools-weaver
92 changes: 92 additions & 0 deletions tools/oas-mcp-tools-weaver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<div align="center">
<img src="weaver-logo.png" alt="OAS MCP Tools Weaver Logo" width="400">
</div>

<h1 align="center">
OAS MCP Tools Weaver 🕸️
</h1>

<p align="center">
<img alt="Java" src="https://img.shields.io/badge/Java-17%2B-orange.svg?style=for-the-badge&logo=java">
<img alt="OpenAPI" src="https://img.shields.io/badge/OpenAPI-3.0-green?style=for-the-badge&logo=openapi-initiative">
<img alt="MCP" src="https://img.shields.io/badge/MCP-Ready-orange?style=for-the-badge">
<img alt="License" src="https://img.shields.io/badge/License-Apache-purple?style=for-the-badge">
</p>

<p align="center">
Welcome to <strong>OAS MCP Tools Weaver</strong>, a powerful Spring Boot application that serves as a dynamic tool provider for AI models. It parses an OpenAPI 3.0 specification at startup and exposes each API operation as a "tool" that can be invoked by a Large Language Model (LLM). This bridges the gap between your existing RESTful APIs and modern LLMs, enabling them to interact with your services through the standardized <a href="https://github.com/GoogleCloudPlatform/genai-toolbox/blob/main/mcp/spec/McpSpec.proto">Model-Context-Protocol (MCP)</a>.
</p>

---

## 🏛️ Architecture & Workflow
LLMs can be augmented with "tools" that allow them to interact with external systems. The Model-Context-Protocol (MCP) provides a standard for defining these tools. The **OAS MCP Tools Weaver** is a Spring Boot server that dynamically exposes your OpenAPI-defined APIs as MCP-compliant tools for LLMs.
This server dynamically exposes your OpenAPI-defined APIs as tools for LLMs.

The workflow is simple:

1. **Configuration**: You place your OpenAPI 3.0 specification file (`spec.json` or `spec.yaml`) inside the application's resources and configure a `ToolCallbackProvider` bean for it.
2. **Startup**: On startup, the Spring Boot application parses the OpenAPI specification, extracting API endpoints, parameters, and request/response schemas.
3. **Tool Exposure**: The server dynamically creates and exposes an MCP-compliant "tool" for each API operation. It intelligently handles complex schemas (e.g., `oneOf`, `allOf`) to make them understandable to LLMs.
4. **Interaction**: An LLM can now discover and invoke these tools. The server translates the LLM's tool call into a live HTTP request to your backend API, including authentication, and returns the result.

<div align="center">
<img src="architecture.png" alt="Workflow Diagram" width="800">
</div>

## ✨ Key Features

* ✅ **Dynamic Tool Serving**: No need to manually generate static tool files. Tools are created at runtime directly from your OAS.
* ✅ **OpenAPI 3.0 Support**: Works with the industry-standard API specification format.
* ✅ **Intelligent Schema Handling**: Simplifies complex JSON schemas (`oneOf`, `allOf`) from the OAS, making them easier for LLMs to consume.
* ✅ **Enterprise Ready**: Built with Java and Spring Boot, a robust and widely-adopted stack for enterprise-grade applications.
* ✅ **MCP Compliant**: Adheres to the Model-Context-Protocol for standardized tool interaction with LLMs.

## 🚀 Getting Started

Follow these steps to install and run the tool.

### Prerequisites

* Java 17 or higher
* Apache Maven
* An OpenAPI 3.0 specification file for your API.

### Installation

1. **Clone the repository:**
```bash
git clone https://github.com/your-repo/oas-mcp-tools-weaver.git
cd oas-mcp-tools-weaver/mcpserver
```

2. **Place your OpenAPI Specification:**
Copy your OpenAPI specification file (e.g., `my-api.yaml`) into the `src/main/resources/openapi/` directory.

3. **Configure the Tool Provider:**
You must create a `ToolCallbackProvider` bean for your OpenAPI specification. Open the relevant Spring configuration file and add a bean definition similar to the following:

```bash
@Bean
ToolCallbackProvider myApiTools(OASSchemaHandler schemaProcessor, RestTemplate restTemplate) {
return new DynamicOpenApiToolCallbackProvider("/openapi/my-api.yaml", schemaProcessor, restTemplate, apiUrlEnv);
}
```

### Usage

The server is run as a standard Spring Boot application using Maven.

1. **Set Environment Variables:**
Before running, ensure you have set the required environment variables.
```bash
export API_ENV_URL="https://your.api.backend.com"
```

2. **Run the Application:**
Navigate to the `mcpserver` directory and execute the following Maven command:
```bash
mvn spring-boot:run
```

The server will start (by default on port `8081`) and will be ready to serve tools to your LLM.
Binary file added tools/oas-mcp-tools-weaver/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions tools/oas-mcp-tools-weaver/mcpserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Use a multi-stage build to keep the final image size small

# Stage 1: Build the application
FROM maven:3.8.6-eclipse-temurin-17 AS builder

# Set the working directory inside the container
WORKDIR /app

# Copy the pom.xml and install dependencies
COPY pom.xml .
RUN mvn dependency:go-offline

# Copy the source code
COPY src ./src

# Package the application
RUN mvn package -DskipTests

# Stage 2: Create the final image
FROM eclipse-temurin:17-jdk-jammy

# Set the working directory inside the container
WORKDIR /app

# Copy the jar file from the builder stage
COPY --from=builder /app/target/*.jar app.jar

# Expose port 8080
EXPOSE 8081

# Run the application
ENTRYPOINT ["java", "-jar", "app.jar"]
41 changes: 41 additions & 0 deletions tools/oas-mcp-tools-weaver/mcpserver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# MCP Server

## Introduction

This MCP Server is a Spring Boot application that serves as a dynamic tool provider for AI models, enabling them to interact with backend APIs. It works by parsing an OpenAPI specification at startup and creating a corresponding "tool" for each API operation defined.

These tools can then be invoked by a Large Language Model (LLM) to perform actions, effectively allowing the LLM to use the API to fulfill tasks. The server handles the translation from the LLM's tool call into a live HTTP request to the target API, including authentication. A key feature is its ability to process and simplify complex JSON schemas (e.g., `oneOf`, `allOf`) from the OpenAPI specification, making them easier for the LLM to understand and use correctly.

## Architecture Diagram

![architecture_diagram.png](architecture_diagram.png?raw=true "MCP Server Architecture Diagram")

## How to Run

1. **Prerequisites**:
* Java 17 or later
* Apache Maven

2. **Configuration**:

* Before starting the application, keep your OpenAPI Specs under [src/main/resources/openapi/](src/main/resources/openapi/) directory.
* Ensure you're creating a ToolCallbackProvider Bean for your OAS. For example:

```java
@Bean
ToolCallbackProvider flightSearch(OASSchemaHandler schemaProcessor, RestTemplate restTemplate) {
return new DynamicOpenApiToolCallbackProvider("/openapi/your-oas-spec.yaml", schemaProcessor, restTemplate, apiUrlEnv);
}
```

* Make sure you have set the below environment variable:

* `API_ENV_URL`: Your API Environment URL value.

3. **Run the application**:

Navigate to the project's root directory and execute the following Maven command:
```bash
mvn spring-boot:run
```
The server will start on the port `8081`.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading