Skip to content

refactor: extract shared utilities from duplicated gmail/outlook code#4

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1781199325-refactor-shared-utilities
Open

refactor: extract shared utilities from duplicated gmail/outlook code#4
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1781199325-refactor-shared-utilities

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Both gmail-mcp and outlook-mcp duplicated three patterns. This PR extracts them into a new shared/permit0_mcp_shared package.

What was duplicated → what it became:

Pattern Before After
Authenticated HTTP client gmail.py and graph.py each had ~15 identical lines (get token → build headers → httpx.request → error check → return json) AuthenticatedClient(base_url, error_label, get_token) in permit0_mcp_shared.http
Server creation + transport dispatch Both server.py had identical FastMCP(name, host=env(…), port=env(…)) + identical main() function create_server(name) and run_server(server) in permit0_mcp_shared.server
JSON response formatting json.dumps(obj, indent=2, ensure_ascii=False) repeated ~25× across both servers to_json(obj) in permit0_mcp_shared.response

Usage after refactoring (gmail.py as example):

from permit0_mcp_shared.http import AuthenticatedClient
from .auth import get_token

_client = AuthenticatedClient(
    base_url="https://gmail.googleapis.com/gmail/v1/users/me",
    error_label="gmail",
    get_token=get_token,
)
call = _client.call  # drop-in replacement for the old `call()` function

Docker build context changed from per-package (gmail-mcp/) to repo root (.) so the shared package is available during COPY. Dockerfiles and docker-compose.yml updated accordingly; the docker build commands in README.md and docs/ are updated too.

Both servers still register exactly 13 tools each — verified by importing and counting.

Link to Devin session: https://app.devin.ai/sessions/88887f3b436449c2923a19a56c1c5c88
Requested by: @fafaisland

Create permit0-mcp-shared package with three modules:
- http.AuthenticatedClient: token-based HTTP wrapper (was duplicated in
  gmail.py and graph.py)
- server.create_server/run_server: FastMCP creation and MCP_TRANSPORT
  dispatch (was duplicated in both server.py main() functions)
- response.to_json: json.dumps(obj, indent=2, ensure_ascii=False) helper
  (was repeated ~25 times across both server.py files)

Update both servers to import from the shared package. Update Dockerfiles
to use repo-root build context so the shared package is available during
image builds. Update docker-compose.yml accordingly.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant