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
68 changes: 68 additions & 0 deletions .github/workflows/code-health-mcp-server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: 'Code Health MCP Server'
on:
push:
branches:
- main
paths:
- 'tools/mcp-server/**'
- '.github/workflows/code-health-mcp-server.yml'
pull_request:
branches:
- main
paths:
- 'tools/mcp-server/**'
- '.github/workflows/code-health-mcp-server.yml'
workflow_dispatch: {}
workflow_call: {}

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout MCP Server
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
- name: Install Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c
with:
go-version-file: 'tools/mcp-server/go.mod'
- name: Build MCP Server
working-directory: tools/mcp-server
run: make build

test:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
- name: Install Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c
with:
go-version-file: 'tools/mcp-server/go.mod'
- name: Run tests
working-directory: tools/mcp-server
run: make test

lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
sparse-checkout: |
.github
tools
- name: Install Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c
with:
go-version-file: 'tools/mcp-server/go.mod'
cache: false # see https://github.com/golangci/golangci-lint-action/issues/807
- name: golangci-lint
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20
with:
version: v2.11.4
working-directory: tools/mcp-server

47 changes: 47 additions & 0 deletions tools/cli/pkg/openapi/openapi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2026 MongoDB Inc
//
// 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.

// Package openapi provides public interfaces for loading and saving OpenAPI specifications.
// This package wraps the internal openapi package to provide a stable public API.
package openapi

import (
"github.com/mongodb/openapi/tools/cli/internal/openapi"
"github.com/oasdiff/kin-openapi/openapi3"
"github.com/oasdiff/oasdiff/load"
"github.com/spf13/afero"
)

// Loader provides methods for loading OpenAPI specifications from files.
type Loader struct {
impl *openapi.OpenAPI3
}

// NewLoader creates a new OpenAPI loader.
func NewLoader() *Loader {
return &Loader{
impl: openapi.NewOpenAPI3(),
}
}

// LoadFromPath loads an OpenAPI spec from the given file path.
func (l *Loader) LoadFromPath(path string) (*load.SpecInfo, error) {
return l.impl.CreateOpenAPISpecFromPath(path)
}

// SaveToFile saves an OpenAPI spec to a file in the specified format.
// Format can be "json", "yaml", or "all".
func SaveToFile(path, format string, spec *openapi3.T, fs afero.Fs) error {
return openapi.Save(path, spec, format, fs)
}
6 changes: 6 additions & 0 deletions tools/go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.26

use (
mcp-server
cli
)
125 changes: 125 additions & 0 deletions tools/mcp-server/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
version: "2"
run:
modules-download-mode: readonly
tests: true
linters:
default: none
enable:
- copyloopvar
- dogsled
- errcheck
- errorlint
- exhaustive
- funlen
- gocritic
- godot
- goprintffuncname
- gosec
- govet
- ineffassign
- lll
- makezero
- misspell
- nakedret
- noctx
- nolintlint
- perfsprint
- prealloc
- predeclared
- revive
- rowserrcheck
- staticcheck
- testifylint
- thelper
- unconvert
- unused
- whitespace
settings:
funlen:
lines: 360
statements: 120
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
govet:
enable:
- shadow
lll:
line-length: 150
misspell:
locale: US
nestif:
min-complexity: 7
revive:
severity: warning
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: defer
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: early-return
- name: errorf
- name: exported
- name: import-shadowing
- name: indent-error-flow
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: struct-tag
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
- name: unused-receiver
- name: constant-logical-expr
- name: confusing-naming
- name: unnecessary-stmt
- name: use-any
- name: imports-blocklist
arguments:
- github.com/pkg/errors
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gci
- gofmt
- goimports
settings:
gci:
sections:
- standard
- default
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$

46 changes: 46 additions & 0 deletions tools/mcp-server/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.PHONY: build
build: ## Build the MCP server binary
@echo "==> Building mcp-server binary"
go build -o bin/mcp-server ./cmd

.PHONY: install
install: ## Install the MCP server binary to GOPATH/bin
@echo "==> Installing mcp-server"
go install ./cmd

##@ Development

.PHONY: fmt
fmt: ## Format Go code
@echo "==> Formatting code"
gofmt -w -s .

.PHONY: lint
lint: ## Run linter
@echo "==> Running linter"
golangci-lint run

.PHONY: test
test: ## Run tests
@echo "==> Running tests"
go test -v ./...

##@ Cleanup

.PHONY: clean
clean: ## Remove build artifacts
@echo "==> Cleaning build artifacts"
rm -rf bin/

##@ Dependencies

.PHONY: deps
deps: ## Download dependencies
@echo "==> Downloading dependencies"
go mod download

.PHONY: tidy
tidy: ## Tidy go.mod
@echo "==> Tidying go.mod"
go mod tidy

46 changes: 46 additions & 0 deletions tools/mcp-server/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"context"
"log"
"os"

"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/mongodb/openapi/tools/mcp-server/internal/registry"
"github.com/mongodb/openapi/tools/mcp-server/internal/tools"
)

const (
serverName = "openapi-mcp-server"
serverVersion = "0.1.0"
)

func main() {
if err := run(); err != nil {
log.Fatalf("Error: %v", err)
}
}

func run() error {
reg := registry.New()

impl := &mcp.Implementation{
Name: serverName,
Version: serverVersion,
}
server := mcp.NewServer(impl, nil)

tools.Register(server, reg)

// Log to stderr (stdout is reserved for MCP protocol)
log.SetOutput(os.Stderr)
log.Printf("Starting %s v%s", serverName, serverVersion)

transport := &mcp.StdioTransport{}
session, err := server.Connect(context.Background(), transport, nil)
if err != nil {
return err
}

return session.Wait()
}
43 changes: 43 additions & 0 deletions tools/mcp-server/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module github.com/mongodb/openapi/tools/mcp-server

go 1.26

require (
github.com/modelcontextprotocol/go-sdk v1.5.0
github.com/mongodb/openapi/tools/cli v0.0.0
github.com/oasdiff/kin-openapi v0.136.4
github.com/spf13/afero v1.15.0
)

require (
cloud.google.com/go v0.123.0 // indirect
github.com/go-openapi/jsonpointer v0.22.5 // indirect
github.com/go-openapi/swag/jsonname v0.25.5 // indirect
github.com/google/jsonschema-go v0.4.2 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mailru/easyjson v0.9.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/oasdiff/oasdiff v1.12.7 // indirect
github.com/oasdiff/yaml v0.0.4 // indirect
github.com/oasdiff/yaml3 v0.0.4 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/segmentio/asm v1.1.3 // indirect
github.com/segmentio/encoding v0.5.4 // indirect
github.com/tidwall/gjson v1.18.0 // indirect
github.com/tidwall/match v1.2.0 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
github.com/wI2L/jsondiff v0.7.0 // indirect
github.com/woodsbury/decimal128 v1.4.0 // indirect
github.com/yargevad/filepathx v1.0.0 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
go.uber.org/mock v0.6.0 // indirect
golang.org/x/oauth2 v0.35.0 // indirect
golang.org/x/sys v0.42.0 // indirect
golang.org/x/text v0.35.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/mongodb/openapi/tools/cli => ../cli
Loading
Loading