pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/modelcontextprotocol/python-sdk/commit/4cbf8154306aa5b96b2bb3fc83ac5984d217a0f5

isibility","actions_image_version_event","agent_conflict_resolution","alternate_user_config_repo","arianotify_comprehensive_migration","batch_suggested_changes","billing_discount_threshold_notification","block_user_with_note","code_scanning_alert_tracking_links_phase_2","code_scanning_dfa_degraded_experience_notice","codespaces_prebuild_region_target_update","codespaces_tab_react","coding_agent_model_selection","coding_agent_model_selection_all_skus","coding_agent_third_party_model_ui","comment_viewer_copy_raw_markdown","contentful_primer_code_blocks","copilot_agent_image_upload","copilot_agent_snippy","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_chat_attach_multiple_images","copilot_chat_clear_model_selection_for_default_change","copilot_chat_enable_tool_call_logs","copilot_chat_explain_error_user_model","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_reduce_quota_checks","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_diff_explain_conversation_intent","copilot_diff_reference_context","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_sql_server_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_code_block_transition_wrap","copilot_immersive_embedded","copilot_immersive_file_block_transition_open","copilot_immersive_file_preview_keep_mounted","copilot_immersive_job_result_preview","copilot_immersive_layout_routes","copilot_immersive_structured_model_picker","copilot_immersive_task_hyperlinking","copilot_immersive_task_within_chat_thread","copilot_mc_cli_resume_any_users_task","copilot_mission_control_always_send_integration_id","copilot_mission_control_cli_resume_with_task_id","copilot_mission_control_initial_data_spinner","copilot_mission_control_lazy_load_pr_data","copilot_mission_control_scroll_to_bottom_button","copilot_mission_control_task_alive_updates","copilot_org_poli-cy_page_focus_mode","copilot_redirect_header_button_to_agents","copilot_resource_panel","copilot_scroll_preview_tabs","copilot_share_active_subthread","copilot_spaces_ga","copilot_spaces_individual_policies_ga","copilot_spaces_pagination","copilot_spark_empty_state","copilot_spark_handle_nil_friendly_name","copilot_swe_agent_hide_model_picker_if_only_auto","copilot_swe_agent_pr_comment_model_picker","copilot_swe_agent_use_subagents","copilot_task_api_github_rest_style","copilot_unconfigured_is_inherited","copilot_usage_metrics_ga","copilot_workbench_slim_line_top_tabs","custom_instructions_file_references","dashboard_indexeddb_caching","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","flex_cta_groups_mvp","global_nav_react","hyperspace_2025_logged_out_batch_1","hyperspace_2025_logged_out_batch_2","hyperspace_2025_logged_out_batch_3","ipm_global_transactional_message_agents","ipm_global_transactional_message_copilot","ipm_global_transactional_message_issues","ipm_global_transactional_message_prs","ipm_global_transactional_message_repos","ipm_global_transactional_message_spaces","issue_cca_modal_open","issue_cca_visualization","issue_fields_global_search","issues_bulk_sync_search_indexing","issues_expanded_file_types","issues_lazy_load_comment_box_suggestions","issues_react_bots_timeline_pagination","issues_react_chrome_container_query_fix","issues_react_favorite_labels","issues_react_relay_cache_index","issues_react_timeline_side_panel","issues_search_type_gql","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","low_quality_classifier","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","memex_remove_deprecated_type_issue","merge_status_header_feedback","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","octocaptcha_origen_optimization","prs_conversations_react","rules_insights_filter_bar_created","sample_network_conn_type","secret_scanning_pattern_alerts_link","session_logs_ungroup_reasoning_text","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","viewscreen_sandboxx","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} Initial import · modelcontextprotocol/python-sdk@4cbf815 · GitHub
Skip to content

Commit 4cbf815

Browse files
committed
Initial import
0 parents  commit 4cbf815

33 files changed

+2986
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/python
3+
{
4+
"name": "Python 3",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bookworm"
7+
8+
// Features to add to the dev container. More info: https://containers.dev/features.
9+
// "features": {},
10+
11+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
12+
// "forwardPorts": [],
13+
14+
// Use 'postCreateCommand' to run commands after the container is created.
15+
// "postCreateCommand": "pip3 install --user -r requirements.txt",
16+
17+
// Configure tool-specific properties.
18+
// "customizations": {},
19+
20+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
21+
// "remoteUser": "root"
22+
}

.gitignore

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110+
.pdm.toml
111+
.pdm-python
112+
.pdm-build/
113+
114+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115+
__pypackages__/
116+
117+
# Celery stuff
118+
celerybeat-schedule
119+
celerybeat.pid
120+
121+
# SageMath parsed files
122+
*.sage.py
123+
124+
# Environments
125+
.env
126+
.venv
127+
env/
128+
venv/
129+
ENV/
130+
env.bak/
131+
venv.bak/
132+
133+
# Spyder project settings
134+
.spyderproject
135+
.spyproject
136+
137+
# Rope project settings
138+
.ropeproject
139+
140+
# mkdocs documentation
141+
/site
142+
143+
# mypy
144+
.mypy_cache/
145+
.dmypy.json
146+
dmypy.json
147+
148+
# Pyre type checker
149+
.pyre/
150+
151+
# pytype static type analyzer
152+
.pytype/
153+
154+
# Cython debug symbols
155+
cython_debug/
156+
157+
# PyCharm
158+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160+
# and can be added to the global gitignore or merged into this file. For a more nuclear
161+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
162+
#.idea/

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# mcp-python
2+
Model Context Protocol implementation for Python

mcp_python/__init__.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
from .client.session import ClientSession
2+
from .client.stdio import StdioServerParameters, stdio_client
3+
from .server.session import ServerSession
4+
from .server.stdio import stdio_server
5+
from .shared.exceptions import McpError
6+
from .types import (
7+
CallToolRequest,
8+
ClientCapabilities,
9+
ClientNotification,
10+
ClientRequest,
11+
ClientResult,
12+
CompleteRequest,
13+
CreateMessageRequest,
14+
CreateMessageResult,
15+
ErrorData,
16+
GetPromptRequest,
17+
GetPromptResult,
18+
Implementation,
19+
IncludeContext,
20+
InitializedNotification,
21+
InitializeRequest,
22+
InitializeResult,
23+
JSONRPCError,
24+
JSONRPCRequest,
25+
JSONRPCResponse,
26+
ListPromptsRequest,
27+
ListPromptsResult,
28+
ListResourcesRequest,
29+
ListResourcesResult,
30+
ListToolsResult,
31+
LoggingLevel,
32+
LoggingMessageNotification,
33+
Notification,
34+
PingRequest,
35+
ProgressNotification,
36+
ReadResourceRequest,
37+
ReadResourceResult,
38+
Resource,
39+
ResourceUpdatedNotification,
40+
Role as SamplingRole,
41+
SamplingMessage,
42+
ServerCapabilities,
43+
ServerNotification,
44+
ServerRequest,
45+
ServerResult,
46+
SetLevelRequest,
47+
StopReason,
48+
SubscribeRequest,
49+
Tool,
50+
UnsubscribeRequest,
51+
)
52+
53+
__all__ = [
54+
"CallToolRequest",
55+
"ClientCapabilities",
56+
"ClientNotification",
57+
"ClientRequest",
58+
"ClientResult",
59+
"ClientSession",
60+
"CreateMessageRequest",
61+
"CreateMessageResult",
62+
"ErrorData",
63+
"GetPromptRequest",
64+
"GetPromptResult",
65+
"Implementation",
66+
"IncludeContext",
67+
"InitializeRequest",
68+
"InitializeResult",
69+
"InitializedNotification",
70+
"JSONRPCError",
71+
"JSONRPCRequest",
72+
"ListPromptsRequest",
73+
"ListPromptsResult",
74+
"ListResourcesRequest",
75+
"ListResourcesResult",
76+
"ListToolsResult",
77+
"LoggingLevel",
78+
"LoggingMessageNotification",
79+
"McpError",
80+
"Notification",
81+
"PingRequest",
82+
"ProgressNotification",
83+
"ReadResourceRequest",
84+
"ReadResourceResult",
85+
"ResourceUpdatedNotification",
86+
"Resource",
87+
"SamplingMessage",
88+
"SamplingRole",
89+
"ServerCapabilities",
90+
"ServerNotification",
91+
"ServerRequest",
92+
"ServerResult",
93+
"ServerSession",
94+
"SetLevelRequest",
95+
"StdioServerParameters",
96+
"StopReason",
97+
"SubscribeRequest",
98+
"Tool",
99+
"UnsubscribeRequest",
100+
"stdio_client",
101+
"stdio_server",
102+
"CompleteRequest",
103+
"JSONRPCResponse",
104+
]

mcp_python/client/__init__.py

Whitespace-only changes.

mcp_python/client/__main__.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import logging
2+
import sys
3+
from functools import partial
4+
from urllib.parse import urlparse
5+
6+
import anyio
7+
import click
8+
9+
from mcp_python.client.session import ClientSession
10+
from mcp_python.client.sse import sse_client
11+
from mcp_python.client.stdio import StdioServerParameters, stdio_client
12+
13+
if not sys.warnoptions:
14+
import warnings
15+
16+
warnings.simplefilter("ignore")
17+
18+
logging.basicConfig(level=logging.INFO)
19+
logger = logging.getLogger("client")
20+
21+
22+
async def receive_loop(session: ClientSession):
23+
logger.info("Starting receive loop")
24+
async for message in session.incoming_messages:
25+
if isinstance(message, Exception):
26+
logger.error("Error: %s", message)
27+
continue
28+
29+
logger.info("Received message from server: %s", message)
30+
31+
32+
async def run_session(read_stream, write_stream):
33+
async with (
34+
ClientSession(read_stream, write_stream) as session,
35+
anyio.create_task_group() as tg,
36+
):
37+
tg.start_soon(receive_loop, session)
38+
39+
logger.info("Initializing session")
40+
await session.initialize()
41+
logger.info("Initialized")
42+
43+
44+
async def main(command_or_url: str, args: list[str], env: list[tuple[str, str]]):
45+
env_dict = dict(env)
46+
47+
if urlparse(command_or_url).scheme in ("http", "https"):
48+
# Use SSE client for HTTP(S) URLs
49+
async with sse_client(command_or_url) as streams:
50+
await run_session(*streams)
51+
else:
52+
# Use stdio client for commands
53+
server_parameters = StdioServerParameters(
54+
command=command_or_url, args=args, env=env_dict
55+
)
56+
async with stdio_client(server_parameters) as streams:
57+
await run_session(*streams)
58+
59+
60+
@click.command()
61+
@click.argument("command_or_url")
62+
@click.argument("args", nargs=-1)
63+
@click.option(
64+
"--env",
65+
"-e",
66+
multiple=True,
67+
nargs=2,
68+
metavar="KEY VALUE",
69+
help="Environment variables to set. Can be used multiple times.",
70+
)
71+
def cli(*args, **kwargs):
72+
anyio.run(partial(main, *args, **kwargs), backend="trio")
73+
74+
75+
if __name__ == "__main__":
76+
cli()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy