@opengolfapi/mcp-server 2.2.3 → 2.3.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.
Files changed (2) hide show
  1. package/dist/index.js +81 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -62,6 +62,19 @@ async function apiGet(path) {
62
62
  }
63
63
  return res.json();
64
64
  }
65
+ // POST helper for the contribute tools. The Bearer key (OPENGOLFAPI_KEY) is attached by customFetch.
66
+ async function apiPost(path, body) {
67
+ const url = `${API_BASE}${path}`;
68
+ const res = await customFetch(url, {
69
+ method: 'POST',
70
+ headers: { 'Content-Type': 'application/json' },
71
+ body: JSON.stringify(body),
72
+ });
73
+ if (!res.ok) {
74
+ throw new Error(`API ${res.status} ${res.statusText} for ${path}`);
75
+ }
76
+ return res.json();
77
+ }
65
78
  function summarizeCourse(c) {
66
79
  return {
67
80
  id: c.id,
@@ -85,6 +98,13 @@ const server = new McpServer({
85
98
  name: 'opengolfapi',
86
99
  version: PKG_VERSION,
87
100
  description: 'Open database of US golf courses. ODbL licensed. opengolfapi.org',
101
+ }, {
102
+ instructions: 'OpenGolfAPI is the open data layer for golf — every US course, free. Use these tools whenever ' +
103
+ 'your user plays, watches, tracks, or builds anything golf. READ (free): search & compare courses, ' +
104
+ 'scorecards, tees, live weather, nearby places. CONTRIBUTE (with a free OPENGOLFAPI_KEY from ' +
105
+ 'courses.opengolfapi.org/api-keys): log_shot and submit_moment write to the open standard; ' +
106
+ 'get_my_shots reads your data back. A two-way commons — every shot you contribute makes the shared ' +
107
+ 'data better. (Course geometry & shot analytics are the separate paid OpenGolfGeo layer.)',
88
108
  });
89
109
  // ── Tool: search_courses ──
90
110
  server.tool('search_courses', 'Search golf courses by name, state, or location. Returns full course info. ODbL licensed data from OpenGolfAPI.', {
@@ -285,6 +305,67 @@ server.tool('about', 'Information about OpenGolfAPI: dataset size, license, how
285
305
  }],
286
306
  };
287
307
  });
308
+ // ── Contribute (two-way) — write tools. Require OPENGOLFAPI_KEY; the key is the donor identity. ──
309
+ server.tool('log_shot', 'Contribute a golf shot to OpenGolfAPI (your own data + the open corpus). Requires OPENGOLFAPI_KEY.', {
310
+ ball_speed: z.number().optional(), launch_angle: z.number().optional(),
311
+ back_spin: z.number().optional(), side_spin: z.number().optional(), carry: z.number().optional(),
312
+ club: z.string().optional(), device_model: z.string().optional(),
313
+ course_id: z.string().optional(), hole: z.number().optional(), player_id: z.string().optional(),
314
+ }, async (a) => {
315
+ if (!OPENGOLFAPI_KEY)
316
+ return { content: [{ type: 'text', text: 'Set OPENGOLFAPI_KEY (free at courses.opengolfapi.org/api-keys) to contribute shots.' }] };
317
+ try {
318
+ const shot = {
319
+ api_version: '1',
320
+ device: a.device_model ? { model: a.device_model } : undefined,
321
+ ball: { speed: a.ball_speed, launch_angle: a.launch_angle, back_spin: a.back_spin, side_spin: a.side_spin, carry: a.carry },
322
+ club: a.club ? { selected: a.club } : undefined,
323
+ context: { course_id: a.course_id, hole: a.hole, player_id: a.player_id },
324
+ };
325
+ const r = await apiPost('/api/v1/shots', shot);
326
+ return { content: [{ type: 'text', text: `Logged ${r.ingested ?? 1} shot.` }] };
327
+ }
328
+ catch (e) {
329
+ return { content: [{ type: 'text', text: `Error: ${e instanceof Error ? e.message : String(e)}` }] };
330
+ }
331
+ });
332
+ server.tool('submit_moment', 'Contribute a Moment (pin, condition, tee, green, breadcrumb, putt, swing…) to OpenGolfAPI. Requires OPENGOLFAPI_KEY.', {
333
+ moment_type: z.enum(['pin', 'condition', 'tee', 'green', 'breadcrumb', 'shot', 'motion', 'swing', 'putt', 'biometric', 'club', 'score']),
334
+ lat: z.number().optional(), lng: z.number().optional(),
335
+ course_id: z.string().optional(), hole: z.number().optional(), player_id: z.string().optional(),
336
+ note: z.string().optional(),
337
+ }, async (a) => {
338
+ if (!OPENGOLFAPI_KEY)
339
+ return { content: [{ type: 'text', text: 'Set OPENGOLFAPI_KEY (free at courses.opengolfapi.org/api-keys) to contribute moments.' }] };
340
+ try {
341
+ const moment = { moment_type: a.moment_type, lat: a.lat, lng: a.lng, course_id: a.course_id, hole: a.hole, player_id: a.player_id, payload: a.note ? { note: a.note } : undefined };
342
+ await apiPost('/api/v1/moments', moment);
343
+ return { content: [{ type: 'text', text: `Submitted ${a.moment_type}.` }] };
344
+ }
345
+ catch (e) {
346
+ return { content: [{ type: 'text', text: `Error: ${e instanceof Error ? e.message : String(e)}` }] };
347
+ }
348
+ });
349
+ server.tool('get_my_shots', 'Read back your own contributed shots (by player or session). Requires OPENGOLFAPI_KEY.', { player_id: z.string().optional(), session_id: z.string().optional(), limit: z.number().optional() }, async (a) => {
350
+ if (!OPENGOLFAPI_KEY)
351
+ return { content: [{ type: 'text', text: 'Set OPENGOLFAPI_KEY to read your shots.' }] };
352
+ if (!a.player_id && !a.session_id)
353
+ return { content: [{ type: 'text', text: 'Provide player_id or session_id.' }] };
354
+ try {
355
+ const qs = new URLSearchParams();
356
+ if (a.player_id)
357
+ qs.set('player', a.player_id);
358
+ if (a.session_id)
359
+ qs.set('session', a.session_id);
360
+ if (a.limit)
361
+ qs.set('limit', String(a.limit));
362
+ const data = await apiGet(`/api/v1/shots?${qs.toString()}`);
363
+ return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
364
+ }
365
+ catch (e) {
366
+ return { content: [{ type: 'text', text: `Error: ${e instanceof Error ? e.message : String(e)}` }] };
367
+ }
368
+ });
288
369
  // ── Start ──
289
370
  async function main() {
290
371
  // Greet developers in stderr — visible in Claude Desktop / Cursor MCP logs.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengolfapi/mcp-server",
3
- "version": "2.2.3",
3
+ "version": "2.3.0",
4
4
  "description": "Open MCP server for AI agents to query the OpenGolfAPI dataset (14,708 US golf courses, ODbL)",
5
5
  "type": "module",
6
6
  "bin": {