-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
125 lines (105 loc) · 5.02 KB
/
Copy pathMakefile
File metadata and controls
125 lines (105 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
.PHONY: build test test-race vet lint fmt tidy install regen-examples smoke clean release-snapshot
BINARY := openapi-go-mcp
BIN_DIR := bin
# Flags passed to every generator invocation in `regen-examples`. -force
# tells the generator to overwrite the existing *.mcp.go files (which is
# exactly what we want when regenerating); leaving it off would make
# regen-examples fail on second run.
GEN_FLAGS := -force
build:
@mkdir -p $(BIN_DIR)
go build -o $(BIN_DIR)/$(BINARY) ./cmd/$(BINARY)
test:
go test ./...
test-race:
go test ./... -race -count=1
vet:
go vet ./...
lint:
golangci-lint run
fmt:
gofmt -s -w .
tidy:
go mod tidy
install:
go install ./cmd/$(BINARY)
# Refresh every example's generated code. Requires oapi-codegen on PATH.
regen-examples: build
oapi-codegen -config examples/petstore/gen/pet/oapi.yaml examples/petstore/petstore.yaml
$(BIN_DIR)/$(BINARY) $(GEN_FLAGS) \
-spec examples/petstore/petstore.yaml \
-out examples/petstore/gen/petmcp \
-package petmcp \
-client-import github.com/dipjyotimetia/openapi-go-mcp/examples/petstore/gen/pet
$(BIN_DIR)/$(BINARY) $(GEN_FLAGS) \
-spec testdata/petstore-v2.json \
-emit-v3 examples/swagger2-petstore/petstore-v3.yaml
oapi-codegen -config examples/swagger2-petstore/gen/pet/oapi.yaml examples/swagger2-petstore/petstore-v3.yaml
$(BIN_DIR)/$(BINARY) $(GEN_FLAGS) \
-spec examples/swagger2-petstore/petstore-v3.yaml \
-out examples/swagger2-petstore/gen/petmcp \
-package petmcp \
-client-import github.com/dipjyotimetia/openapi-go-mcp/examples/swagger2-petstore/gen/pet
oapi-codegen -config examples/users-api/gen/users/oapi.yaml examples/users-api/users-api.yaml
$(BIN_DIR)/$(BINARY) $(GEN_FLAGS) \
-spec examples/users-api/users-api.yaml \
-out examples/users-api/gen/usersmcp \
-package usersmcp \
-client-import github.com/dipjyotimetia/openapi-go-mcp/examples/users-api/gen/users
$(BIN_DIR)/$(BINARY) $(GEN_FLAGS) \
-spec examples/library/library-v2.json \
-emit-v3 examples/library/library-v3.yaml
oapi-codegen -config examples/library/gen/library/oapi.yaml examples/library/library-v3.yaml
$(BIN_DIR)/$(BINARY) $(GEN_FLAGS) \
-spec examples/library/library-v3.yaml \
-out examples/library/gen/librarymcp \
-package librarymcp \
-client-import github.com/dipjyotimetia/openapi-go-mcp/examples/library/gen/library
oapi-codegen -config examples/complex/gen/complex/oapi.yaml examples/complex/complex.yaml
$(BIN_DIR)/$(BINARY) $(GEN_FLAGS) \
-spec examples/complex/complex.yaml \
-out examples/complex/gen/complexmcp \
-package complexmcp \
-client-import github.com/dipjyotimetia/openapi-go-mcp/examples/complex/gen/complex
oapi-codegen -config examples/non-json-bodies/gen/nonjson/oapi.yaml examples/non-json-bodies/non-json-bodies.yaml
$(BIN_DIR)/$(BINARY) $(GEN_FLAGS) \
-spec examples/non-json-bodies/non-json-bodies.yaml \
-out examples/non-json-bodies/gen/nonjsonmcp \
-package nonjsonmcp \
-client-import github.com/dipjyotimetia/openapi-go-mcp/examples/non-json-bodies/gen/nonjson
oapi-codegen -config examples/todos/gen/todos/oapi.yaml examples/todos/todos.yaml
$(BIN_DIR)/$(BINARY) $(GEN_FLAGS) \
-spec examples/todos/todos.yaml \
-out examples/todos/gen/todosmcp \
-package todosmcp \
-client-import github.com/dipjyotimetia/openapi-go-mcp/examples/todos/gen/todos
# Quick smoke test: initialise the petstore (go-sdk) MCP server over stdio
# and list tools. Use `make smoke-all` to exercise both backends.
smoke: build
@out=$$(mktemp); trap 'rm -f "$$out"' 0; \
( printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"smoke","version":"0"}}}'; \
sleep 1; \
printf '%s\n' '{"jsonrpc":"2.0","method":"notifications/initialized","params":{}}'; \
printf '%s\n' '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}'; \
sleep 2 ) | go run ./examples/petstore > "$$out"; \
grep -q '"id":1,"result"' "$$out"; \
grep -q '"id":2,"result"' "$$out"; \
cat "$$out"
# Broader smoke: exercise the mark3labs backend too, ensuring the two
# adapter paths stay in lockstep at the protocol layer.
smoke-all: build smoke
@echo "--- smoke (mark3labs adapter) ---"
@out=$$(mktemp); trap 'rm -f "$$out"' 0; \
( printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"smoke","version":"0"}}}'; \
sleep 1; \
printf '%s\n' '{"jsonrpc":"2.0","method":"notifications/initialized","params":{}}'; \
printf '%s\n' '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}'; \
sleep 2 ) | go run ./examples/petstore-mark3labs > "$$out"; \
grep -q '"id":1,"result"' "$$out"; \
grep -q '"id":2,"result"' "$$out"; \
cat "$$out"
clean:
rm -rf $(BIN_DIR) dist coverage.out
# Validate the goreleaser config without publishing. Useful before tagging.
release-snapshot:
go run github.com/goreleaser/goreleaser/v2@latest release --snapshot --clean --skip=publish,docker