@opengolfapi/mcp-server 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OpenGolfAPI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # @opengolfapi/mcp-server
2
+
3
+ Free MCP server for AI agents to query the OpenGolfAPI dataset (16,908 US golf courses).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install -g @opengolfapi/mcp-server
9
+ ```
10
+
11
+ ## Configure
12
+
13
+ Add to your MCP client config:
14
+
15
+ ```json
16
+ {
17
+ "mcpServers": {
18
+ "opengolfapi": {
19
+ "command": "opengolfapi-mcp"
20
+ }
21
+ }
22
+ }
23
+ ```
24
+
25
+ ## Tools
26
+
27
+ - `search_courses(query, state?)` — find courses by name + state
28
+ - `get_course(id)` — full free-tier course record with scorecard
29
+
30
+ For premium data (per-tee ratings, climate, nearby POIs, booking links), see **[GolfAGI](https://golfagi.com)**.
31
+
32
+ ## License
33
+
34
+ MIT
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * OpenGolfAPI MCP Server — Free tier.
4
+ *
5
+ * 2 tools: search_courses, get_course
6
+ * Returns only open/free fields.
7
+ *
8
+ * Install: npx @opengolfapi/mcp-server
9
+ * Or connect via: npx tsx mcp-server/opengolf.ts
10
+ */
11
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * OpenGolfAPI MCP Server — Free tier.
4
+ *
5
+ * 2 tools: search_courses, get_course
6
+ * Returns only open/free fields.
7
+ *
8
+ * Install: npx @opengolfapi/mcp-server
9
+ * Or connect via: npx tsx mcp-server/opengolf.ts
10
+ */
11
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
12
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
13
+ import { z } from 'zod';
14
+ import { createClient } from '@supabase/supabase-js';
15
+ const SUPABASE_URL = process.env.SUPABASE_URL ?? 'https://ysbzokxixabqrdogdvqc.supabase.co';
16
+ const SUPABASE_KEY = process.env.SUPABASE_SERVICE_ROLE_KEY ?? '';
17
+ if (!SUPABASE_KEY) {
18
+ console.error('SUPABASE_SERVICE_ROLE_KEY required');
19
+ process.exit(1);
20
+ }
21
+ const supabase = createClient(SUPABASE_URL, SUPABASE_KEY);
22
+ const FREE_FIELDS = 'id, course_name, latitude, longitude, state, city, course_type, par_total, phone, website, year_built, address, postal_code';
23
+ const server = new McpServer({
24
+ name: 'opengolfapi',
25
+ version: '1.0.0',
26
+ description: 'Open database of 17,000+ US golf courses. Free, ODbL licensed. opengolfapi.org',
27
+ });
28
+ // ── Tool: search_courses ──
29
+ server.tool('search_courses', 'Search golf courses by name, state, or location. Returns basic course info. Free, ODbL licensed data from OpenGolfAPI.', {
30
+ lat: z.number().optional().describe('Latitude for geo search'),
31
+ lng: z.number().optional().describe('Longitude for geo search'),
32
+ radius_mi: z.number().optional().default(25).describe('Search radius in miles'),
33
+ query: z.string().optional().describe('Course name search'),
34
+ state: z.string().optional().describe('2-letter US state code'),
35
+ limit: z.number().optional().default(10).describe('Max results'),
36
+ }, async ({ lat, lng, radius_mi, query: q, state, limit }) => {
37
+ let query = supabase.from('golf_courses').select(FREE_FIELDS);
38
+ if (q)
39
+ query = query.ilike('course_name', `%${q}%`);
40
+ if (state)
41
+ query = query.eq('state', state.toUpperCase());
42
+ if (lat !== undefined && lng !== undefined) {
43
+ const r = radius_mi ?? 25;
44
+ const latDelta = r / 69.0;
45
+ const lngDelta = r / (69.0 * Math.cos(lat * Math.PI / 180));
46
+ query = query
47
+ .gte('latitude', lat - latDelta).lte('latitude', lat + latDelta)
48
+ .gte('longitude', lng - lngDelta).lte('longitude', lng + lngDelta);
49
+ }
50
+ const { data } = await query.limit(limit ?? 10);
51
+ const courses = (data ?? []).map((c) => ({
52
+ id: c.id,
53
+ name: c.course_name,
54
+ city: c.city,
55
+ state: c.state,
56
+ lat: c.latitude,
57
+ lng: c.longitude,
58
+ type: c.course_type,
59
+ par: c.par_total,
60
+ phone: c.phone,
61
+ website: c.website,
62
+ }));
63
+ return {
64
+ content: [{
65
+ type: 'text',
66
+ text: JSON.stringify({
67
+ courses,
68
+ total: courses.length,
69
+ source: 'OpenGolfAPI (opengolfapi.org) — ODbL licensed',
70
+ upgrade: 'Tee ratings, climate, weather, booking → golfagi.com/api',
71
+ }, null, 2),
72
+ }],
73
+ };
74
+ });
75
+ // ── Tool: get_course ──
76
+ server.tool('get_course', 'Get detailed golf course info including scorecard. Free, ODbL licensed. For tee ratings, climate, weather, booking → golfagi.com/api', {
77
+ course_id: z.string().describe('Course UUID from search results'),
78
+ }, async ({ course_id }) => {
79
+ const [courseRes, holesRes] = await Promise.all([
80
+ supabase.from('golf_courses').select(FREE_FIELDS).eq('id', course_id).single(),
81
+ supabase.from('golf_course_holes').select('hole_number, par').eq('course_id', course_id).not('par', 'is', null).order('hole_number'),
82
+ ]);
83
+ if (courseRes.error || !courseRes.data) {
84
+ return { content: [{ type: 'text', text: 'Course not found' }] };
85
+ }
86
+ const c = courseRes.data;
87
+ const scorecard = (holesRes.data ?? []).map(h => ({
88
+ hole: h.hole_number,
89
+ par: h.par,
90
+ }));
91
+ return {
92
+ content: [{
93
+ type: 'text',
94
+ text: JSON.stringify({
95
+ id: c.id,
96
+ name: c.course_name,
97
+ city: c.city,
98
+ state: c.state,
99
+ lat: c.latitude,
100
+ lng: c.longitude,
101
+ type: c.course_type,
102
+ par: c.par_total,
103
+ holes: scorecard.length,
104
+ phone: c.phone,
105
+ website: c.website,
106
+ year_built: c.year_built,
107
+ address: c.address,
108
+ postal_code: c.postal_code,
109
+ scorecard,
110
+ source: 'OpenGolfAPI (opengolfapi.org) — ODbL licensed',
111
+ upgrade: 'Tee ratings, slopes, yardages, climate, weather, nearby hotels, booking → golfagi.com/api',
112
+ }, null, 2),
113
+ }],
114
+ };
115
+ });
116
+ // ── Start ──
117
+ async function main() {
118
+ const transport = new StdioServerTransport();
119
+ await server.connect(transport);
120
+ }
121
+ main().catch(console.error);
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@opengolfapi/mcp-server",
3
+ "version": "1.0.0",
4
+ "description": "Free MCP server for AI agents to query the OpenGolfAPI dataset",
5
+ "type": "module",
6
+ "bin": {
7
+ "opengolfapi-mcp": "dist/index.js"
8
+ },
9
+ "files": ["dist", "README.md", "LICENSE"],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "prepublishOnly": "npm run build"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/opengolfapi/mcp-server.git"
17
+ },
18
+ "keywords": ["mcp", "golf", "opengolfapi", "ai"],
19
+ "author": "OpenGolfAPI",
20
+ "license": "MIT",
21
+ "bugs": { "url": "https://github.com/opengolfapi/mcp-server/issues" },
22
+ "homepage": "https://opengolfapi.org",
23
+ "dependencies": {
24
+ "@modelcontextprotocol/sdk": "^1.0.0",
25
+ "@supabase/supabase-js": "^2.0.0",
26
+ "zod": "^3.22.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^20.0.0",
30
+ "typescript": "^5.0.0"
31
+ }
32
+ }