跪拜 Guibai
← All articles
MCP · AIGC

MCP Server Development, Demystified with a macOS Maps Search Tool

By 李小轰_Rex ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

MCP is the protocol that lets AI assistants call external tools, and a working server can be written in a few dozen lines. This example gives developers a clear template for turning any local command or script into a model-invocable tool, without needing a cloud API key.

Summary

MCP (Model Context Protocol) is the wire protocol that lets AI models call external tools. This example walks through a complete MCP server that opens Apple Maps for a location query. The server registers a single tool `search_map`, which takes a `query` string. When an AI assistant receives a request like 'Search West Lake scenic area in the map', it invokes the tool, and the server builds an Apple Maps URL and hands it to the system's `open` command, bringing the Maps app to the foreground.

The code is split into three files: `package.json` points to the entry `src/index.js`, which uses the official `@modelcontextprotocol/server` SDK and Zod for parameter definitions. `src/maps.js` contains only the map-specific logic, keeping the protocol layer separate. Configuration in Cursor is done via `.cursor/mcp.json`, either project-level or user-level. Publishing to npm is straightforward: `npm login` and `npm publish`, after which users can run it via `npx -y local-maps-mcp` or a global install.

The example deliberately keeps tooling minimal, showing that MCP servers don't require complex infrastructure. The use of the system's `open` command means no API key is needed, and it works entirely on the local machine. The article also covers the distinction between project-level and user-level MCP configuration, which is useful when working across multiple environments.

Takeaways
— MCP servers communicate with AI tools via stdin/stdout (stdio); protocol messages go to stdout, logs to stderr.
— The example server registers a single tool `search_map` with a required string parameter `query`, using Zod for validation.
— The server uses the `@modelcontextprotocol/server` SDK to create the server and handle the protocol.
— For the actual map action, it builds an Apple Maps URL like `https://maps.apple.com/?q=西湖景区` and opens it with `/usr/bin/open -b com.apple.Maps`.
— No map API key is required because it relies on the system's `open` command.
— Configuration in Cursor: project-level `.cursor/mcp.json` or user-level `~/.cursor/mcp.json`; project-level takes precedence.
— Publishing to npm: use `npm login --registry https://registry.npmjs.org` and `npm publish --registry https://registry.npmjs.org`.
— Users can install and run the published package with `npx -y local-maps-mcp` or a global `npm install -g` followed by `local-maps-mcp`.
Conclusions

The separation between protocol handling and business logic in this example (index.js vs maps.js) is a pattern that scales to more complex MCP servers.

Using system commands like `open` avoids API key overhead but ties the tool to macOS, showing the trade-off between simplicity and portability.

Concepts & terms
MCP (Model Context Protocol)
An open protocol that standardizes how AI models interact with external tools. It defines how a tool is registered, invoked, and how results are returned, allowing any MCP-compatible client to use the tool.
stdio
Standard input/output. MCP servers communicate with the AI tool by reading from stdin and writing to stdout; logs are written to stderr.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗