Skip to main content

MCPS (MCP Secure) integration for LangChain -- cryptographic identity and trust verification for AI agents.

Project description

langchain-mcps

MCPS (MCP Secure) integration for LangChain -- cryptographic identity and trust verification for AI agents.

Add zero-trust identity verification to any LangChain agent or chain with one line of code.

Install

pip install langchain-mcps

Quick Start

Callback Handler (recommended)

Attach to any LangChain agent or chain via callbacks:

from mcp_secure import generate_key_pair, create_passport, sign_passport
from langchain_mcps import MCPSCallbackHandler

# Generate keys and create a signed passport
authority_keys = generate_key_pair()
agent_keys = generate_key_pair()
passport = create_passport(
    name="my-agent",
    version="1.0.0",
    public_key=agent_keys["public_key"],
)
signed_passport = sign_passport(passport, authority_keys["private_key"])

# Create the handler
handler = MCPSCallbackHandler(
    passport=signed_passport,
    authority_public_key=authority_keys["public_key"],
    private_key=agent_keys["private_key"],  # optional: signs actions
)

# Use with any LangChain chain or agent
result = my_chain.invoke(
    {"question": "What is MCPS?"},
    config={"callbacks": [handler]},
)

# Check verification status and audit log
print(handler.is_verified)  # True
print(handler.audit_log)    # [{timestamp, event, action, ...}, ...]

Middleware Wrapper

Wrap any LangChain Runnable with a verification gate:

from langchain_mcps import with_mcps

secure_chain = with_mcps(my_chain, signed_passport, authority_keys["public_key"])
result = secure_chain.invoke({"question": "hello"})
# Raises PermissionError if passport is invalid, expired, or revoked

Features

  • Identity verification -- ECDSA P-256 passport verification before any agent action
  • Action signing -- cryptographically sign every chain/tool invocation
  • Trust levels -- enforce minimum trust (L0 Unsigned through L4 Audited)
  • Revocation checks -- optional live revocation via AgentSign Trust Authority
  • Audit trail -- full log of verified/rejected events
  • Replay protection -- nonce-based replay attack prevention
  • Zero config -- works with any LangChain Runnable (chains, agents, tools)

Trust Levels

Level Name Meaning
L0 UNSIGNED No verification
L1 IDENTIFIED Agent has a passport
L2 VERIFIED Passport signature verified
L3 SCANNED Agent code passed OWASP scan
L4 AUDITED Full security audit completed

API

MCPSCallbackHandler

Parameter Type Default Description
passport dict required Signed agent passport
authority_public_key str required Trust Authority PEM public key
private_key str None Agent PEM private key (for signing)
min_trust_level int 1 Minimum trust level to accept
verify_revocation bool False Check live revocation status
trust_authority str "https://agentsign.dev" Trust Authority URL
on_verified callable None Callback on successful verification
on_rejected callable None Callback on failed verification
on_action callable None Callback with signed action envelopes

with_mcps(chain, passport, authority_public_key, **kwargs)

Convenience wrapper. Returns an MCPSChainWrapper with .invoke(), .ainvoke(), .stream(), .batch().

Related

License

MIT -- CyberSecAI Ltd

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_mcps-0.1.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_mcps-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file langchain_mcps-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_mcps-0.1.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for langchain_mcps-0.1.0.tar.gz
Algorithm Hash digest
SHA256 221dc43456f53c1139434fc13536cef58c04a9d7fe8e712d030f17f8b79208e2
MD5 c3b72d5aa3a9eace070cbe2fe2358ada
BLAKE2b-256 94d9db7c7f17c1e639777a0fde84ff84de569e8f3c4607c9017c4e7a505bd5be

See more details on using hashes here.

File details

Details for the file langchain_mcps-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: langchain_mcps-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for langchain_mcps-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f713de01553569296b477db6a99544f5315c234e973bb0a8b6fe48b9041ccf1c
MD5 7d3dd376b3b03d608512a4910fa14860
BLAKE2b-256 f858422aa696f72b4b7e0a4f0ddfd4afdc602c0ec12be373e6944f6e8e6ee2c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page