René's URL Explorer Experiment


Title: Feature Proposal: Secure Tool/Resource/Prompt Decorators with Auth + Encrypted I/O · Issue #1305 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: Feature Proposal: Secure Tool/Resource/Prompt Decorators with Auth + Encrypted I/O · Issue #1305 · modelcontextprotocol/python-sdk

X Title: Feature Proposal: Secure Tool/Resource/Prompt Decorators with Auth + Encrypted I/O · Issue #1305 · modelcontextprotocol/python-sdk

Description: Description 🚀 Feature Request I would like to propose adding a secure wrapper layer to @mcp.tool, @mcp.resource, and @mcp.prompt that supports: Authentication (Auth) Ability to pass an auth function (e.g. verify_identity()) that can vali...

Open Graph Description: Description 🚀 Feature Request I would like to propose adding a secure wrapper layer to @mcp.tool, @mcp.resource, and @mcp.prompt that supports: Authentication (Auth) Ability to pass an auth functio...

X Description: Description 🚀 Feature Request I would like to propose adding a secure wrapper layer to @mcp.tool, @mcp.resource, and @mcp.prompt that supports: Authentication (Auth) Ability to pass an auth functio...

Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/1305

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Feature Proposal: Secure Tool/Resource/Prompt Decorators with Auth + Encrypted I/O","articleBody":"### Description\n\n🚀 Feature Request\n\nI would like to propose adding a secure wrapper layer to @mcp.tool, @mcp.resource, and @mcp.prompt that supports:\n\n1. Authentication (Auth)\n\nAbility to pass an auth function (e.g. verify_identity()) that can validate JWT, Certs, or TEE Attestation before executing the function.\n\nAuthentication should be bidirectional - we need to verify both:\n  1. Client authentication - Is the client authorized to use the tool?\n  2. Tool/Server authentication - Is the tool legitimate and trustworthy?\n\n\nIf authentication fails, return a proper MCP Error (e.g. 403 Forbidden).\n\n2. Key Negotiation Mechanism\n\nClient provides a public key (PK) or session token.\n\nServer performs Diffie-Hellman (ECDH) or TLS/mTLS handshake to derive a session key.\n\nSession key is stored in context and used for symmetric encryption/decryption of I/O.\n\n3. Unified Secure Interface\n\nDevelopers could write secure MCP functions like this:\n\n```\n@mcp.secure_tool(auth=verify_identity, encrypt=True)\nasync def trade(symbol: str, amount: float) -\u003e str:\n    return f\"Trade {amount} {symbol} executed\"\n\n```\nAnd the same approach could apply to resource and prompt.\n\n🔹 Example Implementation\n\n```\nimport functools\nfrom mcp.server.fastmcp import FastMCP, tool, resource, prompt\nfrom mcp.server.models import Error\nfrom cryptography.hazmat.primitives.ciphers.aead import AESGCM\nimport os, base64\n\nmcp = FastMCP(\"SecureApp\")\n\n# ========== Simple Key Management ==========\nSESSION_KEY = AESGCM.generate_key(bit_length=128)\naesgcm = AESGCM(SESSION_KEY)\nNONCE_SIZE = 12\n\ndef encrypt(data: str) -\u003e str:\n    nonce = os.urandom(NONCE_SIZE)\n    ct = aesgcm.encrypt(nonce, data.encode(), None)\n    return base64.b64encode(nonce + ct).decode()\n\ndef decrypt(token: str) -\u003e str:\n    raw = base64.b64decode(token)\n    nonce, ct = raw[:NONCE_SIZE], raw[NONCE_SIZE:]\n    pt = aesgcm.decrypt(nonce, ct, None)\n    return pt.decode()\n\n# ========== Auth Function ==========\ndef verify_identity() -\u003e bool:\n    # TODO: implement JWT / CERT / Attestation validation\n    return True\n\n# ========== Decorator Factory ==========\ndef secure_wrapper(deco, auth=None, encrypt_io=False, *args, **kwargs):\n    def decorator(func):\n        @deco(*args, **kwargs)   # wrap original MCP decorator\n        @functools.wraps(func)\n        async def wrapper(*f_args, **f_kwargs):\n            # Auth check\n            if auth and not auth():\n                raise Error(code=403, message=\"Authentication failed\")\n\n            # Decrypt inputs\n            if encrypt_io:\n                f_kwargs = {k: decrypt(v) if isinstance(v, str) else v \n                            for k, v in f_kwargs.items()}\n\n            # Execute\n            result = await func(*f_args, **f_kwargs) if callable(func) else func\n\n            # Encrypt outputs\n            if encrypt_io and isinstance(result, str):\n                result = encrypt(result)\n\n            return result\n        return wrapper\n    return decorator\n\n# Three secure variants\ndef secure_tool(auth=None, encrypt_io=False, *args, **kwargs):\n    return secure_wrapper(tool, auth, encrypt_io, *args, **kwargs)\n\ndef secure_resource(auth=None, encrypt_io=False, *args, **kwargs):\n    return secure_wrapper(resource, auth, encrypt_io, *args, **kwargs)\n\ndef secure_prompt(auth=None, encrypt_io=False, *args, **kwargs):\n    return secure_wrapper(prompt, auth, encrypt_io, *args, **kwargs)\n\n# ========== Usage Example ==========\n@secure_tool(auth=verify_identity, encrypt_io=True)\nasync def add(a: int, b: int) -\u003e str:\n    return f\"sum={a+b}\"\n\n@secure_resource(\"secure://greet/{name}\", auth=verify_identity, encrypt_io=True)\ndef greeting(name: str) -\u003e str:\n    return f\"Hello, {name}!\"\n\n@secure_prompt(auth=verify_identity, encrypt_io=True)\ndef greet_user(name: str) -\u003e str:\n    return f\"Write a secure greeting for {name}\"\n\n```\n\n🔹 Encrypted I/O Flow\n\nInput: client encrypts arguments with session key → sends\n\nServer: decrypts args → executes function\n\nOutput: result encrypted → returned to client\n\nClient: decrypts result with the same session key\n\n\n✅ Summary\n\ntool, resource, and prompt can all uniformly support auth + encrypted I/O.\n\nImplemented via decorator factory pattern, keeping code clean.\n\nSupports pluggable JWT, Cert, TEE Attestation validation.\n\nSession key negotiation can use TLS/mTLS or ECDH.\n\nThis would make MCP safer to use in environments where sensitive data and secure tool execution are required.\n\n\n\n### References\n\n[_MR_](https://github.com/modelcontextprotocol/python-sdk/pull/1309) https://github.com/modelcontextprotocol/python-sdk/pull/1309","author":{"url":"https://github.com/wenhuizhang","@type":"Person","name":"wenhuizhang"},"datePublished":"2025-08-25T03:58:23.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/1305/python-sdk/issues/1305"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:c8470d79-ff36-e5b2-a066-381a0fd973b4
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD710:C6842:10DA77:16BFA9:6A626B1C
html-safe-noncedaeb696b7aaf384c53571cc57c72182416b315d2ffcd3b0bf26fd5870e683300
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzEwOkM2ODQyOjEwREE3NzoxNkJGQTk6NkE2MjZCMUMiLCJ2aXNpdG9yX2lkIjoiMTgxNTIwODIwMjUwNzY2MTA5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac95b379ef01988696e61632ed2c0004d4dd772c7e31ba835f47570be3e7752ff2
hovercard-subject-tagissue:3350320551
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/1305/issue_layout
twitter:imagehttps://opengraph.githubassets.com/e938bb6b9c48aaf9f672194fcd136c1cd7ac703fdb79390a090351e2e4898916/modelcontextprotocol/python-sdk/issues/1305
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/e938bb6b9c48aaf9f672194fcd136c1cd7ac703fdb79390a090351e2e4898916/modelcontextprotocol/python-sdk/issues/1305
og:image:altDescription 🚀 Feature Request I would like to propose adding a secure wrapper layer to @mcp.tool, @mcp.resource, and @mcp.prompt that supports: Authentication (Auth) Ability to pass an auth functio...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamewenhuizhang
hostnamegithub.com
expected-hostnamegithub.com
None19769ef9d383a84eeab48bb9b309078c20f4532b73eae2f9713b18406513e0ad
turbo-cache-controlno-preview
go-importgithub.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git
octolytics-dimension-user_id182288589
octolytics-dimension-user_loginmodelcontextprotocol
octolytics-dimension-repository_id862584018
octolytics-dimension-repository_nwomodelcontextprotocol/python-sdk
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id862584018
octolytics-dimension-repository_network_root_nwomodelcontextprotocol/python-sdk
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release76dc6b11f13eaeec1329217c9f16c262ade27a1e
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/issues/1305#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F1305
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F1305
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=modelcontextprotocol%2Fpython-sdk
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/1305
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/1305
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/1305
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/issues/1305
modelcontextprotocol https://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Notifications https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Fork 3.7k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Star 23.7k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Code https://github.com/modelcontextprotocol/python-sdk
Issues 269 https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests 315 https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Security and quality 6 https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
Code https://github.com/modelcontextprotocol/python-sdk
Issues https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Security and quality https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
Feature Proposal: Secure Tool/Resource/Prompt Decorators with Auth + Encrypted I/Ohttps://github.com/modelcontextprotocol/python-sdk/issues/1305#top
authIssues and PRs related to Authentication / OAuthhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22auth%22
enhancementRequest for a new feature that's not currently supportedhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22enhancement%22
https://github.com/wenhuizhang
wenhuizhanghttps://github.com/wenhuizhang
on Aug 25, 2025https://github.com/modelcontextprotocol/python-sdk/issues/1305#issue-3350320551
MRhttps://github.com/modelcontextprotocol/python-sdk/pull/1309
#1309https://github.com/modelcontextprotocol/python-sdk/pull/1309
authIssues and PRs related to Authentication / OAuthhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22auth%22
enhancementRequest for a new feature that's not currently supportedhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22enhancement%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.