You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> **Note**: SSE transport is being superseded by [Streamable HTTP transport](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http).
486
+
487
+
By default, SSE servers are mounted at `/sse` and Streamable HTTP servers are mounted at `/mcp`. You can customize these paths using the methods described below.
488
+
365
489
You can mount the SSE server to an existing ASGI server using the `sse_app` method. This allows you to integrate the SSE server with other ASGI applications.
"""Provide the schema for a specific table, optionally including indexes.
620
+
Example URI: schema://users?include_indexes=true"""
621
+
conn = sqlite3.connect("database.db")
622
+
cursor = conn.cursor()
623
+
try:
624
+
base_query ="SELECT sql FROM sqlite_master WHERE type='table' AND name=?"
625
+
params: list[str] = [table_name]
626
+
if include_indexes:
627
+
cursor.execute(base_query, params)
628
+
schema_parts = cursor.fetchall()
629
+
630
+
index_query = (
631
+
"SELECT sql FROM sqlite_master WHERE type='index' AND tbl_name=?"
632
+
)
633
+
cursor.execute(index_query, params)
634
+
schema_parts.extend(cursor.fetchall())
635
+
else:
636
+
cursor.execute(base_query, params)
637
+
schema_parts = cursor.fetchall()
638
+
639
+
return"\n".join(sql[0] for sql in schema_parts if sql and sql[0])
640
+
finally:
641
+
conn.close()
642
+
643
+
438
644
@mcp.tool()
439
645
defquery_data(sql: str) -> str:
440
646
"""Execute SQL queries safely"""
@@ -555,9 +761,11 @@ if __name__ == "__main__":
555
761
asyncio.run(run())
556
762
```
557
763
764
+
Caution: The `mcp run` and `mcp dev` tool doesn't support low-level server.
765
+
558
766
### Writing MCP Clients
559
767
560
-
The SDK provides a high-level client interface for connecting to MCP servers:
768
+
The SDK provides a high-level client interface for connecting to MCP servers using various [transports](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports):
561
769
562
770
```python
563
771
from mcp import ClientSession, StdioServerParameters, types
@@ -621,6 +829,82 @@ if __name__ == "__main__":
621
829
asyncio.run(run())
622
830
```
623
831
832
+
Clients can also connect using [Streamable HTTP transport](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http):
833
+
834
+
```python
835
+
from mcp.client.streamable_http import streamablehttp_client
836
+
from mcp import ClientSession
837
+
838
+
839
+
asyncdefmain():
840
+
# Connect to a streamable HTTP server
841
+
asyncwith streamablehttp_client("example/mcp") as (
842
+
read_stream,
843
+
write_stream,
844
+
_,
845
+
):
846
+
# Create a session using the client streams
847
+
asyncwith ClientSession(read_stream, write_stream) as session:
The SDK includes [authorization support](https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization) for connecting to protected MCP servers:
857
+
858
+
```python
859
+
from mcp.client.auth import OAuthClientProvider, TokenStorage
860
+
from mcp.client.session import ClientSession
861
+
from mcp.client.streamable_http import streamablehttp_client
862
+
from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata, OAuthToken
0 commit comments