Skip to main content
Glama
Mainframe MCP Server

Mainframe MCP Server

by rohittrimale

Mainframe MCP Server

A Model Context Protocol (MCP) server for IBM z/OS mainframes. It exposes the RSE (Remote System Explorer) REST API — read datasets and members (COBOL, JCL, PROC, copybooks), manage datasets, and submit and monitor jobs — as MCP tools.

Because it speaks the MCP protocol, the same server works in every MCP-compatible client: VS Code (GitHub Copilot), Cursor, Claude Desktop, Gemini CLI, and more. Configure it once per client.

It ships as a single pure-Python package (httpx, no PowerShell) exposing 31 tools, so it runs anywhere — Linux containers, macOS, Windows — and is publishable to PyPI and the MCP Registry.

Install (native package)

pip install mainframe-mcp        # or, from the mcp-server folder: pip install -e .

If public PyPI is blocked, use a mirror, e.g. pip install --index-url https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com mainframe-mcp

This installs a mainframe-mcp command that speaks MCP over stdio.

Related MCP server: mcp-rs232

Configure (native)

Variable

Required

Default

Purpose

MF_HOSTNAME

yes

—

RSE API hostname

MF_PORT

no

443

RSE API port

MF_RSE_BASE_PATH

no

/rseapi/api/v1

API base path

MF_USERNAME

yes

—

TSO user id

MF_PASSWORD

yes

—

TSO password

MF_VERIFY_TLS

no

(off)

1 to verify the server certificate

MF_PDS_LOCATIONS

no

pds_locations.txt beside the module

Segment → dataset map for the get_* tools

MF_SEG_*

no

generic names

Per-site segment names (MF_SEG_COBOL, MF_SEG_COPYBOOK, MF_SEG_CT1, MF_SEG_JCL, MF_SEG_PROC, MF_SEG_JOBDOC) used in pds_locations.txt

MF_READ_ONLY

no

(unset)

1 disables all write/destructive tools

MF_ALLOWED_DSN

no

(unset)

Comma-separated dataset prefixes; write/destructive tools may only target these

MF_AUDIT_LOG

no

logs/audit.log

JSONL audit trail (sensitive fields redacted)

Copy pds_locations.sample.txt to pds_locations.txt and edit it for your site.

Client configuration

The native package installs a mainframe-mcp command. Point your client at it and pass the endpoint + credentials via env.

VS Code (GitHub Copilot)

Add to .vscode/mcp.json in your workspace:

{
  "servers": {
    "mainframe": {
      "type": "stdio",
      "command": "mainframe-mcp",
      "env": {
        "MF_HOSTNAME": "your.host.example.com",
        "MF_USERNAME": "${input:mf_username}",
        "MF_PASSWORD": "${input:mf_password}"
      }
    }
  }
}

Cursor

Add to ~/.cursor/mcp.json (or .cursor/mcp.json in the project):

{
  "mcpServers": {
    "mainframe": {
      "command": "mainframe-mcp",
      "env": {
        "MF_HOSTNAME": "your.host.example.com",
        "MF_USERNAME": "you",
        "MF_PASSWORD": "..."
      }
    }
  }
}

Claude Desktop

Add to claude_desktop_config.json (%APPDATA%\Claude\claude_desktop_config.json):

{
  "mcpServers": {
    "mainframe": {
      "command": "mainframe-mcp",
      "env": {
        "MF_HOSTNAME": "your.host.example.com",
        "MF_USERNAME": "you",
        "MF_PASSWORD": "..."
      }
    }
  }
}

Available tools (31)

Retrieval: get_cobol, get_copybook, get_ct1, get_jcl, get_proc, get_job_docs, get_content, scan_source

Datasets: get_dataset_list, get_dataset_members, get_gdg_versions, search_seq_datasets, create_dataset, create_dataset_like, delete_dataset, rename_dataset, recall_dataset, copy_member, modify_module, upload_member

Jobs: submit_job, submit_jcl_string, get_job_status, get_job_steps, get_job_files, get_job_file_content, get_job_jcl, get_job_notification, get_spool_details, export_spool_to_dataset

TSO: run_tso_command

Architecture

Components:

Layer

File

Role

Transport / entry

server_native.py (main() → mcp.run())

Registers tools, speaks MCP over stdio

Safety layer

mcp_common.py

Intent annotations, read-only mode, confirm guards, scope allowlist, audit

RSE client

rse_client.py

Pure-Python httpx calls to the z/OS RSE REST API

Config

env + pds_locations.txt

Endpoint, credentials, segment → dataset map

What happens on a tool call:

sequenceDiagram
    participant C as MCP client
    participant S as server_native (FastMCP)
    participant W as mf_tool + _run
    participant SF as Safety (mcp_common)
    participant R as RSEClient (httpx)
    participant MF as RSE API
    C->>S: tools/call get_cobol(["PROG1"])
    S->>W: dispatch tool
    W->>SF: _dsn_allowed? / _needs_confirmation?
    alt blocked
        SF-->>C: {status:"error"|"needs_confirmation"}
    else allowed
        W->>W: _client() builds creds (MF_* env)
        W->>R: client.read_member(dsn)
        R->>MF: GET /datasets/{dsn}/content (Basic auth, TLS)
        MF-->>R: 200 + records
        R-->>W: unwrap_records()
        W->>SF: _audit(tool, args, "success", ms)
        W-->>C: {status:"success", data:{...}}
    end

Safety gates, in order:

  1. Registration filter — MF_READ_ONLY=1 means the 10 write + 4 destructive tools are never registered (clients see only the 20 read tools).

  2. Scope allowlist — MF_ALLOWED_DSN rejects out-of-scope datasets before any network call.

  3. Confirm guard — destructive tools return needs_confirmation unless called with confirm=true.

  4. Per-session credentials — creds come from MF_* env (or a per-session override); missing creds return a clean error.

  5. Audit — every call appends a redacted JSONL line (tool, args, status, duration).

The safety layer (mcp_common.py) and RSE client (rse_client.py) are transport-agnostic, so the same tool bodies can be reused behind another transport (e.g. an HTTP/OAuth front end) without changing the mainframe logic.

Deploy

python -m build              # -> dist/mainframe_mcp-<ver>-py3-none-any.whl + .tar.gz
twine upload dist/*          # publish to PyPI

Then submit server.json to the MCP Registry. Users install with pip install mainframe-mcp and point their MCP client at the mainframe-mcp command with MF_HOSTNAME / MF_USERNAME / MF_PASSWORD set (see above).

Hosting over HTTP (Render, Cloud Run, ...)

To run as a hosted service instead of stdio, server_http.py serves the same tools over MCP streamable-HTTP at /mcp, guarded by a bearer token.

Local:

pip install -e ".[http]"
$env:MF_MCP_TOKEN="secret"; $env:MF_HOSTNAME="..."; $env:MF_USERNAME="..."; $env:MF_PASSWORD="..."
python server_http.py     # clients connect to http://localhost:8000/mcp
                          # with header: Authorization: Bearer secret

Render: a Dockerfile and render.yaml are included. In Render → New → Blueprint / Web Service from the (private) repo — it reads render.yaml, generates MF_MCP_TOKEN, and you set MF_HOSTNAME / MF_USERNAME / MF_PASSWORD in the dashboard. Endpoint: https://<your-app>.onrender.com/mcp.

Security: these tools can modify datasets and submit jobs. Keep MF_MCP_TOKEN set, serve only over HTTPS (Render terminates TLS), and prefer MF_READ_ONLY=1 (the render.yaml default). The host must also be able to reach your mainframe's RSE API — a public host cannot reach an internal z/OS system without a tunnel or VPN.

Available Tools

30 tools
copy_memberC

Copy a member from one dataset to another (DATASET(MEMBER) notation).

Inputs: source_dataset (required), destination_dataset (required). Returns: result

create_datasetC

Create a new mainframe dataset.

Inputs: name (required), primary, dsn_type, secondary, +12 more. Returns: result

create_dataset_likeB

Allocate a new dataset with the same attributes as an existing one.

Inputs: new_dataset (required), source_dataset (required), primary, secondary, +3 more. Returns: result

delete_datasetA
Destructive

Delete a mainframe dataset. IRREVERSIBLE. Requires confirm=true.

Inputs: dataset_name (required), confirm. Returns: result

export_spool_to_datasetC

Export a job's spool file (by file id) to a mainframe dataset.

Inputs: job_id (required), file_id (required), job_name (required), destination_dataset (required), +1 more. Returns: result

get_cobolB
Read-only

Retrieve COBOL programs by searching the configured COBOL PDS locations.

Inputs: prog_names (required). Returns: result

get_contentB
Read-only

Fetch dataset/member content. Provide dataset (+optional member), or a comma/space-separated pds_list to search for a member. max_rows truncates.

Inputs: member, dataset, max_rows, pds_list. Returns: result

get_copybookA
Read-only

Retrieve copybook members from the configured copybook PDS locations.

Inputs: copybook_names (required). Returns: result

get_ct1B
Read-only

Retrieve control-card (CT1) members from the configured CT1 PDS locations.

Inputs: ct1_names (required). Returns: result

get_dataset_listA
Read-only

List datasets matching a pattern/filter.

Inputs: dataset_pattern (required). Returns: result

get_gdg_versionsB
Read-only

List generations of a GDG base (via LISTCAT).

Inputs: gdg_base (required). Returns: result

get_jclB
Read-only

Retrieve JCL members from the configured JCL PDS locations.

Inputs: job_names (required). Returns: result

get_job_docsA
Read-only

Retrieve job documentation members from the configured job-doc locations.

Inputs: job_names (required). Returns: result

get_job_file_contentC
Read-only

Read a specific spool file of a job by file id.

Inputs: job_id (required), file_id (required), job_name (required). Returns: result

get_job_filesB
Read-only

List spool/output files (DD names) for a job.

Inputs: job_id (required), job_name (required). Returns: result

get_job_jclB
Read-only

Retrieve the JCL used for a submitted/completed job.

Inputs: job_id (required), job_name (required). Returns: result

get_job_notificationB
Read-only

Check completion-notification status for a job id.

Inputs: job_id (required). Returns: result

get_job_statusB
Read-only

Get the status of a job by name and JES id.

Inputs: job_id (required), job_name (required). Returns: result

get_job_stepsB
Read-only

Get step-level details/return codes for a job.

Inputs: job_id (required), job_name (required). Returns: result

get_procB
Read-only

Retrieve PROC members from the configured PROC PDS locations.

Inputs: proc_names (required). Returns: result

get_spool_detailsA
Read-only

List jobs (and spool details) matching an optional job-name prefix.

Inputs: job_prefix. Returns: result

modify_moduleA
Destructive

Overwrite a dataset member's content. IRREVERSIBLE. Requires confirm=true.

Inputs: content (required), dataset_name (required), confirm. Returns: result

recall_datasetB

Recall a migrated dataset from tape/HSM back to disk.

Inputs: dataset_name (required). Returns: result

rename_datasetA
Destructive

Rename a mainframe dataset. IRREVERSIBLE. Requires confirm=true.

Inputs: new_name (required), old_name (required), confirm. Returns: result

run_tso_commandA
Destructive

Execute an arbitrary TSO command. Can be destructive. Requires confirm=true.

Inputs: command (required), confirm. Returns: result

scan_sourceB
Read-only

Scan a mainframe source path to detect language and references.

Inputs: path (required). Returns: result

search_seq_datasetsC
Read-only

Search sequential datasets matching filter for optional content.

Inputs: filter (required), content, max_results, regex_content, +1 more. Returns: result

submit_jcl_stringC

Submit raw JCL text directly to JES.

Inputs: jcl_text (required). Returns: result

submit_jobB

Submit a JCL job from a PDS member (DATASET(MEMBER)).

Inputs: dataset_member (required), no_notification. Returns: result

upload_memberA

Upload text to a PDS member or sequential dataset. Provide content (preferred for remote use) or a server-side local_file path.

Inputs: target_dataset (required), content, local_file, member_name. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    C2.9/5.0

    Scored across 30 tools

    Disambiguation3/5

    Many tools follow a clear get_<artifact> pattern (COBOL, copybook, CT1, JCL, PROC), and the job-status/spool tools are distinct. However, generic get_content overlaps heavily with the specialized getters, and get_jcl vs get_job_jcl plus upload_member vs modify_module create potential confusion.

    Naming Consistency4/5

    Tool names overwhelmingly use snake_case verb_noun, with clear verbs like get, submit, create, delete. Minor inconsistencies exist (get_cobol vs get_content, search_seq_datasets uses an abbreviation, create_dataset_like) but the pattern is predictable.

    Tool Count2/5

    At 30 tools, the server is over-scoped for a coherent set. Many specialized getters could be consolidated into get_content, and the job-spool area has four overlapping tools. A more focused set of 15-20 would be stronger.

    Completeness4/5

    The set covers dataset lifecycle (create, delete, rename, recall, copy, modify), source retrieval, and full job submission/status/spool flow. Missing member-level deletion and a direct list-members operation are minor gaps.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      MCP server for Redmine project management, enabling tools for managing projects, issues, users, time entries, groups, memberships, versions, wiki, news, attachments, search, and Agile sprints via the Redmine REST API.
      89
      1
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      An MCP server that exposes RS232 serial port connectivity, enabling listing, opening, reading, and writing to serial ports via tools and resources.
      6
      17 PyPI
      MIT
    • F
      license
      Not graded
      quality
      C
      maintenance
      Multi-system MCP server for reading and writing ABAP source via SAP ADT, with write safety controls and a local web admin.
      2
      -