How do I call an MCP server from the command line?

Updated October 2026 · How we answer

Short answerTo call an MCP server from the command line, pipe JSON-RPC messages to a local server process or send them to a remote endpoint with a tool such as curl. Start with initialize, then list tools.

Local servers over stdio

Many local MCP servers run as a command, such as a Node or Python script. You launch the command in your terminal and write one JSON message per line to its standard input. The server replies on standard output, so you can read the answer in the same terminal window.

Keep the process open while you send messages. Closing it ends the session, and the next call starts fresh with no saved state. Some servers print logs to standard error, so check that stream when something fails.

  • Launch the server with its normal start command
  • Send one JSON object per line
  • Read responses from standard output
  • Send tools/list to confirm the connection

Remote servers over HTTP

For a remote server, use a POST request with a JSON body and the required Accept headers. Save any session ID from the response and include it in the next command. Keep the request in a small script so you can rerun it without retyping.

Store secrets in environment variables rather than typing them into the command, since shell history can expose tokens. This also makes it easier to swap keys later.

  • POST JSON with the required headers
  • Pass the session ID on later calls
  • Store tokens in environment variables
  • Keep repeated calls in a script

Common mistakes

  • Forgetting to keep the local process running between messages.
  • Putting API tokens directly into shell commands where they stay in history.
  • Sending several JSON objects on one line, which many servers cannot parse.
From our shopsCASEONYX: Dark-luxe tough phone cases.