@mutallip/google-workspace-mcp 0.0.0-stage → 2.8.1
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.
- package/LICENSE +21 -0
- package/README.md +353 -2
- package/README.npm.md +34 -0
- package/auth/__init__.py +1 -0
- package/auth/auth_info_middleware.py +419 -0
- package/auth/client_secrets.py +76 -0
- package/auth/credential_store.py +598 -0
- package/auth/external_oauth_provider.py +369 -0
- package/auth/gateway_identity.py +164 -0
- package/auth/google_auth.py +1550 -0
- package/auth/google_oauth_provider.py +20 -0
- package/auth/mcp_session_middleware.py +95 -0
- package/auth/oauth21_session_store.py +1332 -0
- package/auth/oauth_callback_server.py +466 -0
- package/auth/oauth_config.py +693 -0
- package/auth/oauth_proxy_config.py +122 -0
- package/auth/oauth_responses.py +230 -0
- package/auth/oauth_types.py +92 -0
- package/auth/permissions.py +330 -0
- package/auth/port_resolver.py +153 -0
- package/auth/request_identity.py +89 -0
- package/auth/scopes.py +369 -0
- package/auth/service_decorator.py +1109 -0
- package/bin/google-workspace-mcp.cjs +123 -0
- package/core/__init__.py +1 -0
- package/core/api_enablement.py +108 -0
- package/core/attachment_storage.py +496 -0
- package/core/camel_case_middleware.py +98 -0
- package/core/cli.py +161 -0
- package/core/comments.py +609 -0
- package/core/config.py +57 -0
- package/core/context.py +43 -0
- package/core/file_limits.py +632 -0
- package/core/gcs_attachment_storage.py +253 -0
- package/core/http_utils.py +339 -0
- package/core/log_formatter.py +270 -0
- package/core/portable_schema_middleware.py +67 -0
- package/core/server.py +1192 -0
- package/core/startup_ui.py +239 -0
- package/core/storage.py +23 -0
- package/core/telemetry.py +194 -0
- package/core/tool_descriptions.py +19 -0
- package/core/tool_registry.py +311 -0
- package/core/tool_tier_loader.py +197 -0
- package/core/tool_tiers.yaml +179 -0
- package/core/toolset_header_middleware.py +67 -0
- package/core/utils.py +1537 -0
- package/core/valkey_storage.py +271 -0
- package/core/warning_filters.py +19 -0
- package/fastmcp_server.py +198 -0
- package/gappsscript/README.md +512 -0
- package/gappsscript/TESTING.md +254 -0
- package/gappsscript/__init__.py +0 -0
- package/gappsscript/apps_script_tools.py +1940 -0
- package/gcalendar/__init__.py +1 -0
- package/gcalendar/calendar_helpers.py +1323 -0
- package/gcalendar/calendar_tools.py +2252 -0
- package/gchat/__init__.py +7 -0
- package/gchat/chat_helpers.py +410 -0
- package/gchat/chat_tools.py +798 -0
- package/gcontacts/__init__.py +1 -0
- package/gcontacts/contacts_helpers.py +765 -0
- package/gcontacts/contacts_tools.py +1685 -0
- package/gdocs/__init__.py +0 -0
- package/gdocs/docs_anchors.py +163 -0
- package/gdocs/docs_comments.py +89 -0
- package/gdocs/docs_helpers.py +2201 -0
- package/gdocs/docs_links.py +87 -0
- package/gdocs/docs_markdown.py +828 -0
- package/gdocs/docs_markdown_writer.py +592 -0
- package/gdocs/docs_plain_text.py +463 -0
- package/gdocs/docs_structure.py +621 -0
- package/gdocs/docs_tables.py +425 -0
- package/gdocs/docs_tools.py +3300 -0
- package/gdocs/managers/__init__.py +18 -0
- package/gdocs/managers/batch_operation_manager.py +1694 -0
- package/gdocs/managers/header_footer_manager.py +526 -0
- package/gdocs/managers/table_operation_manager.py +488 -0
- package/gdocs/managers/validation_manager.py +1504 -0
- package/gdocs/operation_schemas.py +594 -0
- package/gdrive/__init__.py +0 -0
- package/gdrive/drive_helpers.py +1738 -0
- package/gdrive/drive_tools.py +3085 -0
- package/gforms/__init__.py +3 -0
- package/gforms/forms_tools.py +575 -0
- package/gmail/__init__.py +1 -0
- package/gmail/gmail_helpers.py +2107 -0
- package/gmail/gmail_tools.py +4895 -0
- package/gmail/gmail_web_mime.py +441 -0
- package/gsearch/__init__.py +0 -0
- package/gsearch/search_tools.py +253 -0
- package/gsheets/__init__.py +31 -0
- package/gsheets/sheets_helpers.py +2236 -0
- package/gsheets/sheets_tools.py +3280 -0
- package/gslides/__init__.py +0 -0
- package/gslides/slides_digest.py +390 -0
- package/gslides/slides_helpers.py +392 -0
- package/gslides/slides_markup.py +770 -0
- package/gslides/slides_tools.py +376 -0
- package/gtasks/__init__.py +5 -0
- package/gtasks/tasks_tools.py +936 -0
- package/main.py +1170 -0
- package/package.json +43 -4
- package/pyproject.toml +173 -0
- package/uv.lock +2504 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Middleware that narrows the tool set per request via X-MCP-Toolsets / X-MCP-Tools.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from collections.abc import Mapping
|
|
6
|
+
from functools import cache
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
from fastmcp.exceptions import NotFoundError
|
|
10
|
+
from fastmcp.server.dependencies import get_http_headers
|
|
11
|
+
from fastmcp.server.middleware import CallNext, Middleware, MiddlewareContext
|
|
12
|
+
|
|
13
|
+
from core.tool_tier_loader import ToolTierLoader
|
|
14
|
+
|
|
15
|
+
TOOLSETS_HEADER = "x-mcp-toolsets"
|
|
16
|
+
TOOLS_HEADER = "x-mcp-tools"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@cache
|
|
20
|
+
def _toolset_tools() -> dict[str, frozenset[str]]:
|
|
21
|
+
"""Map each service in tool_tiers.yaml to every tool it provides."""
|
|
22
|
+
loader = ToolTierLoader()
|
|
23
|
+
return {
|
|
24
|
+
service: frozenset(loader.get_tools_up_to_tier("complete", [service]))
|
|
25
|
+
for service in loader.get_available_services()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _header_names(headers: Mapping[str, str], header: str) -> set[str]:
|
|
30
|
+
return {
|
|
31
|
+
name.strip().lower()
|
|
32
|
+
for name in headers.get(header, "").split(",")
|
|
33
|
+
if name.strip()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def requested_tools() -> Optional[set[str]]:
|
|
38
|
+
"""Return the tool names the current request's headers allow, or None for no limit."""
|
|
39
|
+
headers = get_http_headers()
|
|
40
|
+
toolsets = _header_names(headers, TOOLSETS_HEADER)
|
|
41
|
+
tools = _header_names(headers, TOOLS_HEADER)
|
|
42
|
+
if not toolsets and not tools:
|
|
43
|
+
return None
|
|
44
|
+
toolset_tools = _toolset_tools()
|
|
45
|
+
return tools.union(*(toolset_tools.get(name, ()) for name in toolsets))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class ToolsetHeaderMiddleware(Middleware):
|
|
49
|
+
"""Hide and refuse tools outside the request's X-MCP-Toolsets / X-MCP-Tools.
|
|
50
|
+
|
|
51
|
+
Only narrows what the server already registered, so a header can never
|
|
52
|
+
expose a tool the operator's configuration removed.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
async def on_list_tools(self, context: MiddlewareContext, call_next: CallNext):
|
|
56
|
+
tools = await call_next(context)
|
|
57
|
+
allowed = requested_tools()
|
|
58
|
+
if allowed is None:
|
|
59
|
+
return tools
|
|
60
|
+
return [tool for tool in tools if tool.name in allowed]
|
|
61
|
+
|
|
62
|
+
async def on_call_tool(self, context: MiddlewareContext, call_next: CallNext):
|
|
63
|
+
allowed = requested_tools()
|
|
64
|
+
name = context.message.name
|
|
65
|
+
if allowed is not None and name not in allowed:
|
|
66
|
+
raise NotFoundError(f"Unknown tool: {name!r}")
|
|
67
|
+
return await call_next(context)
|