# mcp-sh A pure-Bash CLI to interact with any remote [MCP (Model Context Protocol)](https://modelcontextprotocol.io) server over HTTP. **No Node.js. No Go. No install.** Just `curl` + `jq` — already on every macOS and most Linux boxes. List tools, inspect schemas, and call tools directly from your terminal — with full support for OAuth 2.1 PKCE, Bearer, API key, Basic, and client-credentials auth out of the box. ``` $ ./mcp.sh --profile deepwiki --list_tools Found 3 tool(s) on https://mcp.deepwiki.com/mcp: read_wiki_structure Get a list of documentation topics for a GitHub repository. read_wiki_contents View documentation about a GitHub repository. ask_question Ask any question about a GitHub repository and get an AI-powered response. ``` --- ## Why mcp-sh? Most MCP clients require Node.js or a compiled Go binary. `mcp-sh` is a single `.sh` file: - **Zero install** — works on any machine with `bash`, `curl`, and `jq` - **All auth methods** — Bearer, API key, Basic, OAuth 2.0 client credentials, OAuth 2.1 PKCE (browser flow) - **Named profiles** — one config file, switch servers with `--profile` - **CI-friendly** — every value overridable via environment variable - **No more MCP vs CLI fights** - use CLI if you want with a MCP server behind the scene, no dedicated software --- ## Requirements | Tool | Purpose | |------|---------| | `bash` ≥ 3.2 | Shell | | `curl` | HTTP requests | | `jq` | JSON parsing | | `openssl` | PKCE code challenge (OAuth 2.1 only) | | `python3` | URL encoding + OAuth callback server (OAuth 2.1 only) | macOS ships with all of these. On Linux: `apt install curl jq openssl python3` / `yum install ...` --- ## Installation ```bash git clone https://github.com/yourname/mcp-sh cd mcp-sh chmod +x mcp.sh ``` Optionally add to your PATH: ```bash ln -s "$PWD/mcp.sh" /usr/local/bin/mcp ``` --- ## Quick start ```bash # No config needed — pass everything inline ./mcp.sh --url https://mcp.deepwiki.com/mcp --auth none --list_tools # Or set up a profile (recommended) ./mcp.sh --profile deepwiki --list_tools ./mcp.sh --profile deepwiki --describe ask_question ./mcp.sh --profile deepwiki --execute ask_question \ --payload '{"repoName":"anthropics/anthropic-sdk-python","question":"How does streaming work?"}' ``` --- ## Actions | Flag | Description | |------|-------------| | `--list_tools` | List all tools exposed by the server | | `--describe ` | Show `inputSchema`, `outputSchema`, and description | | `--execute ` | Call a tool; combine with `--payload` for arguments | | `--logout` | Clear cached OAuth tokens for the current profile | ### `--list_tools` ```bash ./mcp.sh --profile deepwiki --list_tools ``` ``` Found 3 tool(s) on https://mcp.deepwiki.com/mcp: read_wiki_structure Get a list of documentation topics for a GitHub repository. ... ``` ### `--describe` Displays the full JSON Schema for a tool's inputs, output type, and annotations. ```bash ./mcp.sh --profile exa --describe search ``` ``` Name: search Description: Search the web using Exa AI Input schema: { "type": "object", "properties": { "query": { "type": "string", "description": "Search query" }, "numResults": { "type": "integer", "default": 10 } }, "required": ["query"] } Output: content array (text | image | audio | resource_link | resource) ``` ### `--execute` Calls a tool with a JSON payload. The `--payload` flag defaults to `{}`. ```bash ./mcp.sh --profile exa --execute search \ --payload '{"query": "Model Context Protocol", "numResults": 3}' ``` --- ## Configuration Credentials live in `~/.config/mcp-sh/config` — an INI file with named profiles. The file is never touched by git and should be `chmod 600`. ```bash mkdir -p ~/.config/mcp-sh chmod 700 ~/.config/mcp-sh touch ~/.config/mcp-sh/config chmod 600 ~/.config/mcp-sh/config ``` ### Profile resolution order ``` --profile flag > $MCP_PROFILE env var > "default" profile ``` ### Value resolution order (per field) ``` CLI flag > environment variable > config file > error ``` ### Config file format ```ini [profile-name] url = https://mcp.example.com/mcp auth_method = bearer # see Auth Methods below token = sk-... extra_headers = X-Custom: value # pipe-separate for multiples: H1: v1|H2: v2 ``` --- ## Auth methods ### `none` — no authentication For local servers or open public endpoints. ```ini [local] url = http://localhost:3000/mcp auth_method = none ``` ```bash ./mcp.sh --profile local --list_tools # or inline, no config needed: ./mcp.sh --url http://localhost:3000/mcp --auth none --list_tools ``` **Live public example — [DeepWiki](https://deepwiki.com)** (GitHub repo Q&A, no signup): ```ini [deepwiki] url = https://mcp.deepwiki.com/mcp auth_method = none ``` ```bash ./mcp.sh --profile deepwiki --execute ask_question \ --payload '{ "repoName": "modelcontextprotocol/python-sdk", "question": "What transports are supported?" }' ``` --- ### `bearer` — static Bearer token Sends `Authorization: Bearer ` on every request. ```ini [github] url = https://api.githubcopilot.com/mcp/ auth_method = bearer token = ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ``` Get a free token at [github.com/settings/tokens](https://github.com/settings/tokens) — no special scopes needed for read-only access. ```bash ./mcp.sh --profile github --list_tools ./mcp.sh --profile github --execute get_file_contents \ --payload '{"owner":"anthropics","repo":"anthropic-sdk-python","path":"README.md"}' ``` You can also pass the token at runtime without touching the config file: ```bash MCP_TOKEN=ghp_xxx ./mcp.sh --url https://api.githubcopilot.com/mcp/ --auth bearer --list_tools # or: ./mcp.sh --url https://api.githubcopilot.com/mcp/ --auth bearer --token ghp_xxx --list_tools ``` --- ### `api_key` — custom header key Sends the key in a header of your choice (e.g. `X-API-Key`, `x-api-key`). ```ini [exa] url = https://mcp.exa.ai/mcp auth_method = api_key api_key_header = x-api-key api_key_value = exa-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ``` Get a free key at [dashboard.exa.ai/api-keys](https://dashboard.exa.ai/api-keys). ```bash ./mcp.sh --profile exa --list_tools ./mcp.sh --profile exa --execute search \ --payload '{"query": "open source MCP servers", "numResults": 5}' ``` --- ### `basic` — HTTP Basic Auth Encodes `username:password` as `Authorization: Basic `. ```ini [myservice] url = https://api.myservice.com/mcp auth_method = basic username = alice password = s3cret ``` Or use the combined `credentials` field: ```ini [myservice] url = https://api.myservice.com/mcp auth_method = basic credentials = alice:s3cret ``` ```bash ./mcp.sh --profile myservice --list_tools # runtime override: ./mcp.sh --url https://api.myservice.com/mcp --auth basic --credentials alice:s3cret --list_tools ``` --- ### `oauth2_client_credentials` — machine-to-machine OAuth 2.0 POSTs a `client_credentials` grant to the token endpoint and uses the resulting Bearer token. Suitable for server-to-server integrations where there is no user interaction. ```ini [myplatform] url = https://api.myplatform.com/mcp auth_method = oauth2_client_credentials auth_url = https://auth.myplatform.com/oauth/token client_id = my-client-id client_secret = my-client-secret ``` The `client_id:client_secret` pair can also be written combined: ```ini credentials = my-client-id:my-client-secret ``` ```bash ./mcp.sh --profile myplatform --list_tools # runtime override via env vars: MCP_CREDENTIALS="id:secret" ./mcp.sh \ --url https://api.myplatform.com/mcp \ --auth oauth2_client_credentials \ --auth-url https://auth.myplatform.com/oauth/token \ --list_tools ``` The flow under the hood: ``` POST /oauth/token Authorization: Basic base64(client_id:client_secret) grant_type=client_credentials → { "access_token": "...", "expires_in": 3600 } → Authorization: Bearer ``` --- ### `oauth2_pkce` — OAuth 2.1 Authorization Code + PKCE (browser flow) The most secure auth method. Follows the [MCP Authorization spec](https://modelcontextprotocol.io/specification/draft/basic/authorization/): opens your browser for user consent, receives the callback on `localhost`, exchanges the code for tokens with a PKCE verifier, and caches the result. **Tokens are stored in `~/.config/mcp-sh/tokens/.json` (chmod 600) and auto-refreshed.** ```ini [atlassian] url = https://mcp.atlassian.com/v1/mcp auth_method = oauth2_pkce auth_url = https://mcp.atlassian.com/v1/authorize token_url = https://cf.mcp.atlassian.com/v1/token client_id = GyodEDfMog9jeJ2d redirect_uri = http://localhost:5598/oauth/callback ``` `client_id` `GyodEDfMog9jeJ2d` is Atlassian's pre-registered public MCP client — no app registration required. ```bash # First run — browser opens, you log in, token is cached ./mcp.sh --profile atlassian --list_tools # Subsequent runs — cached token used silently (or auto-refreshed if expired) ./mcp.sh --profile atlassian --execute atlassianUserInfo --payload '{}' ./mcp.sh --profile atlassian --execute searchJiraIssuesUsingJql \ --payload '{"cloudId":"yoursite.atlassian.net","jql":"assignee = currentUser() ORDER BY updated DESC","maxResults":10}' # Force re-authorization ./mcp.sh --profile atlassian --logout ``` **What happens on first run:** ``` 1. Generate PKCE pair code_verifier = <96 random URL-safe chars> code_challenge = BASE64URL(SHA256(code_verifier)) 2. Start local callback server on localhost:5598 3. Open browser → https://mcp.atlassian.com/v1/authorize ?response_type=code &client_id=GyodEDfMog9jeJ2d &redirect_uri=http://localhost:5598/oauth/callback &code_challenge= &code_challenge_method=S256 &resource=https://mcp.atlassian.com/v1/mcp ← RFC 8707 token binding 4. User logs in and consents in browser 5. Atlassian redirects → http://localhost:5598/oauth/callback?code= 6. Exchange code at token endpoint with code_verifier POST https://cf.mcp.atlassian.com/v1/token grant_type=authorization_code&code=...&code_verifier=... 7. Store access_token + refresh_token in ~/.config/mcp-sh/tokens/atlassian.json ``` --- ## MCP session handshake Some servers (Atlassian, and any strict Streamable HTTP implementation) require an `initialize` → `notifications/initialized` handshake before accepting other requests, and return a `Mcp-Session-Id` header that must be included in subsequent calls. `mcp-sh` handles this automatically: it sends `initialize` on startup, captures the session ID from response headers, and includes `Mcp-Session-Id` in every subsequent request. Servers that don't require this (SSE-based servers, local servers) ignore the extra step transparently. --- ## Extra headers Some servers require custom headers beyond authentication. Use `extra_headers` in the profile, pipe-separated for multiples: ```ini [myservice] url = https://api.myservice.com/mcp auth_method = bearer token = sk-xxx extra_headers = X-Tenant-Id: acme|X-API-Version: 2 ``` --- ## Environment variables All config values can be overridden at runtime via environment variables — useful for CI/CD pipelines: | Variable | Overrides | |----------|-----------| | `MCP_CLI_CONFIG` | Path to config file | | `MCP_PROFILE` | Active profile name | | `MCP_URL` | Server URL | | `MCP_AUTH` | Auth method | | `MCP_AUTH_URL` | OAuth token / authorization URL | | `MCP_TOKEN` | Bearer token or API key value | | `MCP_CREDENTIALS` | `client_id:secret` or `user:pass` | ```bash # Example: run in CI without a config file MCP_URL=https://mcp.example.com/mcp \ MCP_AUTH=bearer \ MCP_TOKEN=$MY_SECRET_TOKEN \ ./mcp.sh --list_tools ``` --- ## Tested public MCP servers | Server | URL | Auth | Free | |--------|-----|------|------| | [DeepWiki](https://deepwiki.com) | `https://mcp.deepwiki.com/mcp` | `none` | ✅ | | [Exa](https://exa.ai) | `https://mcp.exa.ai/mcp` | `api_key` (`x-api-key`) | ✅ free tier | | [Firecrawl](https://firecrawl.dev) | `https://mcp.firecrawl.dev/{KEY}/sse` | `bearer` | ✅ 500 credits | | [Tavily](https://tavily.com) | `https://mcp.tavily.com/mcp/` | `bearer` | ✅ free tier | | [GitHub Copilot](https://github.com) | `https://api.githubcopilot.com/mcp/` | `bearer` (PAT) | ✅ | | [Atlassian Rovo](https://www.atlassian.com/rovo) | `https://mcp.atlassian.com/v1/mcp` | `oauth2_pkce` | ✅ | --- ## Protocol notes - Speaks **JSON-RPC 2.0** over HTTP POST - Supports both **SSE** (`text/event-stream`) and **Streamable HTTP** (plain JSON) response formats — auto-detected - Follows **pagination** via `nextCursor` in `tools/list` - Handles all MCP **content types**: `text`, `image`, `audio`, `resource_link`, `resource` - Surfaces both **JSON-RPC errors** (`.error`) and **tool-level errors** (`.result.isError`) --- ## License MIT