langchain-mcp-tools 0.2.0__py3-none-any.whl → 0.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,17 +40,14 @@ except ImportError as e:
40
40
  class McpServerCommandBasedConfig(TypedDict):
41
41
  command: str
42
42
  args: NotRequired[list[str] | None]
43
- env: NotRequired[dict[str, str] | None]
43
+ env: NotRequired[dict[str, str] | None]
44
44
  cwd: NotRequired[str | None]
45
45
  errlog: NotRequired[TextIO | None]
46
46
 
47
47
 
48
48
  class McpServerUrlBasedConfig(TypedDict):
49
49
  url: str
50
- args: NotRequired[list[str] | None]
51
- env: NotRequired[dict[str, str] | None]
52
- cwd: NotRequired[str | None]
53
- errlog: NotRequired[TextIO | None]
50
+ headers: NotRequired[dict[str, str] | None]
54
51
 
55
52
 
56
53
  McpServerConfig = McpServerCommandBasedConfig | McpServerUrlBasedConfig
@@ -103,12 +100,13 @@ async def spawn_mcp_server_and_get_transport(
103
100
  f'initializing with: {server_config}')
104
101
 
105
102
  url_str = str(server_config.get('url')) # None becomes 'None'
103
+ headers = server_config.get("headers", None)
106
104
  # no exception thrown even for a malformed URL
107
105
  url_scheme = urlparse(url_str).scheme
108
106
 
109
107
  if url_scheme in ('http', 'https'):
110
108
  transport = await exit_stack.enter_async_context(
111
- sse_client(url_str)
109
+ sse_client(url_str, headers=headers)
112
110
  )
113
111
 
114
112
  elif url_scheme in ('ws', 'wss'):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langchain-mcp-tools
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Model Context Protocol (MCP) To LangChain Tools Conversion Utility
5
5
  Project-URL: Bug Tracker, https://github.com/hideya/langchain-mcp-tools-py/issues
6
6
  Project-URL: Source Code, https://github.com/hideya/langchain-mcp-tools-py
@@ -30,11 +30,14 @@ This package is intended to simplify the use of
30
30
  server tools with LangChain / Python.
31
31
 
32
32
  [Model Context Protocol (MCP)](https://modelcontextprotocol.io/),
33
- an open source technology
33
+ an open standard
34
34
  [announced by Anthropic](https://www.anthropic.com/news/model-context-protocol),
35
35
  dramatically expands LLM’s scope
36
36
  by enabling external tool and resource integration, including
37
- Google Drive, Slack, Notion, Spotify, Docker, PostgreSQL, and more…
37
+ GitHub, Google Drive, Slack, Notion, Spotify, Docker, PostgreSQL, and more…
38
+
39
+ MCP is likely to become the de facto industry standard as
40
+ [OpenAI has announced its adoption](https://techcrunch.com/2025/03/26/openai-adopts-rival-anthropics-standard-for-connecting-ai-models-to-data).
38
41
 
39
42
  Over 2000 functional components available as MCP servers:
40
43
 
@@ -66,6 +69,9 @@ pip install langchain-mcp-tools
66
69
 
67
70
  ## Quick Start
68
71
 
72
+ A minimal but complete working usage example can be found
73
+ [in this example in the langchain-mcp-tools-py-usage repo](https://github.com/hideya/langchain-mcp-tools-py-usage/blob/main/src/example.py)
74
+
69
75
  `convert_mcp_to_langchain_tools()` utility function accepts MCP server configurations
70
76
  that follow the same structure as
71
77
  [Claude for Desktop](https://modelcontextprotocol.io/quickstart/user),
@@ -102,8 +108,8 @@ The returned tools can be used with LangChain, e.g.:
102
108
  ```python
103
109
  # from langchain.chat_models import init_chat_model
104
110
  llm = init_chat_model(
105
- model='claude-3-7-sonnet-latest',
106
- model_provider='anthropic'
111
+ model="claude-3-7-sonnet-latest",
112
+ model_provider="anthropic"
107
113
  )
108
114
 
109
115
  # from langgraph.prebuilt import create_react_agent
@@ -113,9 +119,6 @@ agent = create_react_agent(
113
119
  )
114
120
  ```
115
121
 
116
- Find complete, minimal working usage examples
117
- [here](https://github.com/hideya/langchain-mcp-tools-py-usage/blob/main/src/example.py)
118
-
119
122
  For hands-on experimentation with MCP server integration,
120
123
  try [this LangChain application built with the utility](https://github.com/hideya/mcp-client-langchain-py)
121
124
 
@@ -138,14 +141,32 @@ For detailed information on how to use this library, please refer to the followi
138
141
  },
139
142
  ```
140
143
 
141
- Note that the key name `"url"` may be changed in the future to match
144
+ Note that the key `"url"` may be changed in the future to match
142
145
  the MCP server configurations used by Claude for Desktop once
143
146
  it introduces remote server support.
144
147
 
148
+ A usage example can be found [here](https://github.com/hideya/langchain-mcp-tools-py-usage/blob/cf96ddc43750708ef3b244bad95714f0f2fe1d28/src/example.py#L43-L54)
149
+
150
+ ### Passing HTTP Headers to SSE Connection
151
+
152
+ A new key `"headers"` has been introduced to pass HTTP headers to the SSE (Server-Sent Events) connection.
153
+ It takes `dict[str, str]` and is primarily intended to support SSE MCP servers
154
+ that require authentication via bearer tokens or other custom headers.
155
+
156
+ ```python
157
+ "sse-server-name": {
158
+ "url": f"http://{sse_server_host}:{sse_server_port}/..."
159
+ "headers": {"Authorization": f"Bearer {bearer_token}"}
160
+ },
161
+ ```
162
+
163
+ The key name `header` is derived from the Python SDK
164
+ [`sse_client()`](https://github.com/modelcontextprotocol/python-sdk/blob/babb477dffa33f46cdc886bc885eb1d521151430/src/mcp/client/sse.py#L24) argument name.
165
+
145
166
  ### Working Directory Configuration for Local MCP Servers
146
167
 
147
- The working directory that is used when spawning a local MCP server
148
- can be specified with the `cwd` key as follows:
168
+ The working directory that is used when spawning a local (stdio) MCP server
169
+ can be specified with the `"cwd"` key as follows:
149
170
 
150
171
  ```python
151
172
  "local-server-name": {
@@ -155,10 +176,13 @@ can be specified with the `cwd` key as follows:
155
176
  },
156
177
  ```
157
178
 
158
- ### Configuration for MCP Server stderr Redirection
179
+ The key name `cwd` is derived from
180
+ Python SDK's [`StdioServerParameters`](https://github.com/modelcontextprotocol/python-sdk/blob/babb477dffa33f46cdc886bc885eb1d521151430/src/mcp/client/stdio/__init__.py#L76-L77).
181
+
182
+ ### Configuration for Local MCP Server `stderr` Redirection
159
183
 
160
- A new key `errlog` has been introduced in to specify a file-like object
161
- to which MCP server's stderr is redirected.
184
+ A new key `"errlog"` has been introduced to specify a file-like object
185
+ to which local (stdio) MCP server's stderr is redirected.
162
186
 
163
187
  ```python
164
188
  log_path = f"mcp-server-{server_name}.log"
@@ -166,18 +190,22 @@ to which MCP server's stderr is redirected.
166
190
  mcp_servers[server_name]["errlog"] = log_file
167
191
  ```
168
192
 
169
- **NOTE: Why the key name `errlog` for `server_config` was chosen:**
193
+ A usage example can be found [here](
194
+ https://github.com/hideya/langchain-mcp-tools-py-usage/blob/cf96ddc43750708ef3b244bad95714f0f2fe1d28/src/example.py#L91-L108)
195
+
196
+ **NOTE: Why the key name `errlog` was chosen:**
170
197
  Unlike TypeScript SDK's `StdioServerParameters`, the Python
171
- SDK's `StdioServerParameters` doesn't include `stderr: int`.
172
- Instead, it calls `stdio_client()` with a separate argument
173
- `errlog: TextIO`. I once included `stderr: int` for
198
+ SDK's `StdioServerParameters` doesn't include `stderr: int`.
199
+ Instead, it calls [`stdio_client()` with a separate argument
200
+ `errlog: TextIO`](https://github.com/modelcontextprotocol/python-sdk/blob/babb477dffa33f46cdc886bc885eb1d521151430/src/mcp/client/stdio/__init__.py#L96).
201
+ I once included `stderr: int` for
174
202
  compatibility with the TypeScript version, but decided to
175
203
  follow the Python SDK more closely.
176
204
 
177
205
  ## Limitations
178
206
 
179
207
  - Currently, only text results of tool calls are supported.
180
- - Fatures other than [Tools](https://modelcontextprotocol.io/docs/concepts/tools) are not supported.
208
+ - MCP features other than [Tools](https://modelcontextprotocol.io/docs/concepts/tools) are not supported.
181
209
 
182
210
  ## Change Log
183
211
 
@@ -0,0 +1,8 @@
1
+ langchain_mcp_tools/__init__.py,sha256=iatHG2fCpz143wgQUZpyFVilgri4yOh2P0vxr22gguE,114
2
+ langchain_mcp_tools/langchain_mcp_tools.py,sha256=txbtjl7BAjZu1ccNUNhLkLd3HNdCSfKeyTCDX_0PUR0,15078
3
+ langchain_mcp_tools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ langchain_mcp_tools-0.2.2.dist-info/licenses/LICENSE,sha256=CRC91e8v116gCpnp7h49oIa6_zjhxqnHFTREeoZFJwA,1072
5
+ langchain_mcp_tools-0.2.2.dist-info/METADATA,sha256=hxlEr_nyHbnjLMzhxYOsT_rZQ8-j4rTi7EDDUxyvb-A,8458
6
+ langchain_mcp_tools-0.2.2.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
7
+ langchain_mcp_tools-0.2.2.dist-info/top_level.txt,sha256=aR_9V2A1Yt-Bca60KmndmGLUWb2wiM5IOG-Gkaf1dxY,20
8
+ langchain_mcp_tools-0.2.2.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- langchain_mcp_tools/__init__.py,sha256=iatHG2fCpz143wgQUZpyFVilgri4yOh2P0vxr22gguE,114
2
- langchain_mcp_tools/langchain_mcp_tools.py,sha256=n4u9fN3_sVMG1CmSKk8FrlXrBt79Ly1tz0TLhmDUaic,15118
3
- langchain_mcp_tools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- langchain_mcp_tools-0.2.0.dist-info/licenses/LICENSE,sha256=CRC91e8v116gCpnp7h49oIa6_zjhxqnHFTREeoZFJwA,1072
5
- langchain_mcp_tools-0.2.0.dist-info/METADATA,sha256=oCzGJZvkhbhF_OA8Pm-Iy2JSjbeIJEEK1cr8pPxxh1g,6808
6
- langchain_mcp_tools-0.2.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
7
- langchain_mcp_tools-0.2.0.dist-info/top_level.txt,sha256=aR_9V2A1Yt-Bca60KmndmGLUWb2wiM5IOG-Gkaf1dxY,20
8
- langchain_mcp_tools-0.2.0.dist-info/RECORD,,