MatteoMass commited on
Commit
9ad58d0
·
1 Parent(s): 3b78b4e

removed the tokens from env

Browse files
app_new.py CHANGED
@@ -1,5 +1,4 @@
1
  import uuid
2
- import asyncio
3
  import os
4
  import gradio as gr
5
 
@@ -9,10 +8,19 @@ from langchain_core.messages import HumanMessage, AIMessage
9
  from mcpc_graph import setup_graph
10
 
11
 
12
- async def chat_logic(message, history, session_state, github_repo, github_token, trello_api, trello_token, hf_token):
 
 
 
 
 
 
 
 
 
13
  """
14
  Handles the main chat logic, including environment setup and streaming responses.
15
-
16
  Args:
17
  message (str): The user's input message.
18
  history (list): The chat history managed by Gradio.
@@ -22,7 +30,7 @@ async def chat_logic(message, history, session_state, github_repo, github_token,
22
  trello_api (str): The Trello API key.
23
  trello_token (str): The Trello API token.
24
  hf_token (str): The Hugging Face API token.
25
-
26
  Yields:
27
  str: The bot's streaming response or an interruption message.
28
  """
@@ -37,17 +45,16 @@ async def chat_logic(message, history, session_state, github_repo, github_token,
37
  if not all([github_repo, github_token, trello_api, trello_token, hf_token]):
38
  yield "Error: Please provide all API keys and the GitHub repository in the 'API Configuration' section before starting the chat."
39
  return
40
-
41
  # Set environment variables for the current process.
42
  os.environ["GITHUB_REPO"] = github_repo
43
- os.environ["GITHUB_TOKEN"] = github_token
44
- os.environ["TRELLO_API_KEY"] = trello_api
45
- os.environ["TRELLO_API_TOKEN"] = trello_token
46
  os.environ["HUGGINGFACE_API_KEY"] = hf_token
47
-
48
  # Asynchronously initialize the graph and store it in the session state
49
  # to reuse it for subsequent messages in the same session.
50
- app, human_resume_node = await setup_graph()
 
 
51
  session_state["app"] = app
52
  session_state["human_resume_node"] = human_resume_node
53
 
@@ -98,7 +105,7 @@ def create_gradio_app():
98
 
99
  with gr.Blocks(theme=gr.themes.Soft(), title="LangGraph Multi-Agent Chat") as demo:
100
  session_state = gr.State({})
101
-
102
  gr.Markdown(
103
  """
104
  # LangGraph Multi-Agent Project Manager
@@ -115,22 +122,54 @@ def create_gradio_app():
115
  bubble_full_width=False,
116
  height=600,
117
  label="Multi-Agent Chat",
118
- show_label=False
119
  )
120
-
121
  # --- FIX: Added an accordion for API keys and configuration ---
122
  with gr.Accordion("API Configuration", open=True):
123
- gr.Markdown("Please enter your credentials. The agent will be configured when you send your first message.")
124
- github_repo = gr.Textbox(label="GitHub Repo", placeholder="e.g., username/repository", info="The target repository for GitHub operations.")
125
- github_token = gr.Textbox(label="GitHub Token", placeholder="ghp_xxxxxxxxxxxx", type="password", info="A fine-grained personal access token.")
126
- trello_api = gr.Textbox(label="Trello API Key", placeholder="Your Trello API key", info="Your API key from trello.com/power-ups/admin.")
127
- trello_token = gr.Textbox(label="Trello Token", placeholder="Your Trello token", type="password", info="A token generated from your Trello account.")
128
- hf_token = gr.Textbox(label="Hugging Face Token", placeholder="hf_xxxxxxxxxxxx", type="password", info="Used for tools requiring Hugging Face models.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
130
  chat_interface = gr.ChatInterface(
131
  fn=chat_logic,
132
  chatbot=chatbot,
133
- additional_inputs=[session_state, github_repo, github_token, trello_api, trello_token, hf_token],
 
 
 
 
 
 
 
134
  title=None,
135
  description=None,
136
  )
@@ -147,4 +186,4 @@ if __name__ == "__main__":
147
  except KeyboardInterrupt:
148
  print("\nShutting down Gradio app.")
149
  except Exception as e:
150
- print(f"An error occurred: {e}")
 
1
  import uuid
 
2
  import os
3
  import gradio as gr
4
 
 
8
  from mcpc_graph import setup_graph
9
 
10
 
11
+ async def chat_logic(
12
+ message,
13
+ history,
14
+ session_state,
15
+ github_repo,
16
+ github_token,
17
+ trello_api,
18
+ trello_token,
19
+ hf_token,
20
+ ):
21
  """
22
  Handles the main chat logic, including environment setup and streaming responses.
23
+
24
  Args:
25
  message (str): The user's input message.
26
  history (list): The chat history managed by Gradio.
 
30
  trello_api (str): The Trello API key.
31
  trello_token (str): The Trello API token.
32
  hf_token (str): The Hugging Face API token.
33
+
34
  Yields:
35
  str: The bot's streaming response or an interruption message.
36
  """
 
45
  if not all([github_repo, github_token, trello_api, trello_token, hf_token]):
46
  yield "Error: Please provide all API keys and the GitHub repository in the 'API Configuration' section before starting the chat."
47
  return
48
+
49
  # Set environment variables for the current process.
50
  os.environ["GITHUB_REPO"] = github_repo
 
 
 
51
  os.environ["HUGGINGFACE_API_KEY"] = hf_token
52
+
53
  # Asynchronously initialize the graph and store it in the session state
54
  # to reuse it for subsequent messages in the same session.
55
+ app, human_resume_node = await setup_graph(
56
+ github_token=github_token, trello_api=trello_api, trello_token=trello_token
57
+ )
58
  session_state["app"] = app
59
  session_state["human_resume_node"] = human_resume_node
60
 
 
105
 
106
  with gr.Blocks(theme=gr.themes.Soft(), title="LangGraph Multi-Agent Chat") as demo:
107
  session_state = gr.State({})
108
+
109
  gr.Markdown(
110
  """
111
  # LangGraph Multi-Agent Project Manager
 
122
  bubble_full_width=False,
123
  height=600,
124
  label="Multi-Agent Chat",
125
+ show_label=False,
126
  )
127
+
128
  # --- FIX: Added an accordion for API keys and configuration ---
129
  with gr.Accordion("API Configuration", open=True):
130
+ gr.Markdown(
131
+ "Please enter your credentials. The agent will be configured when you send your first message."
132
+ )
133
+ github_repo = gr.Textbox(
134
+ label="GitHub Repo",
135
+ placeholder="e.g., username/repository",
136
+ info="The target repository for GitHub operations.",
137
+ )
138
+ github_token = gr.Textbox(
139
+ label="GitHub Token",
140
+ placeholder="ghp_xxxxxxxxxxxx",
141
+ type="password",
142
+ info="A fine-grained personal access token.",
143
+ )
144
+ trello_api = gr.Textbox(
145
+ label="Trello API Key",
146
+ placeholder="Your Trello API key",
147
+ info="Your API key from trello.com/power-ups/admin.",
148
+ )
149
+ trello_token = gr.Textbox(
150
+ label="Trello Token",
151
+ placeholder="Your Trello token",
152
+ type="password",
153
+ info="A token generated from your Trello account.",
154
+ )
155
+ hf_token = gr.Textbox(
156
+ label="Hugging Face Token",
157
+ placeholder="hf_xxxxxxxxxxxx",
158
+ type="password",
159
+ info="Used for tools requiring Hugging Face models.",
160
+ )
161
 
162
  chat_interface = gr.ChatInterface(
163
  fn=chat_logic,
164
  chatbot=chatbot,
165
+ additional_inputs=[
166
+ session_state,
167
+ github_repo,
168
+ github_token,
169
+ trello_api,
170
+ trello_token,
171
+ hf_token,
172
+ ],
173
  title=None,
174
  description=None,
175
  )
 
186
  except KeyboardInterrupt:
187
  print("\nShutting down Gradio app.")
188
  except Exception as e:
189
+ print(f"An error occurred: {e}")
main.py CHANGED
@@ -34,7 +34,7 @@ async def main():
34
  {
35
  "trello": {
36
  "command": "python",
37
- "args": [os.getenv("MCP_TRELLO_PATH")],
38
  "transport": "stdio",
39
  }
40
  }
@@ -43,7 +43,7 @@ async def main():
43
  {
44
  "github": {
45
  "command": "python",
46
- "args": [os.getenv("MCP_GITHUB_PATH")],
47
  "transport": "stdio",
48
  }
49
  }
 
34
  {
35
  "trello": {
36
  "command": "python",
37
+ "args": ["pmcp/mcp_server/trello_server/mcp_trello_main.py"],
38
  "transport": "stdio",
39
  }
40
  }
 
43
  {
44
  "github": {
45
  "command": "python",
46
+ "args": ["pmcp/mcp_server/github_server/mcp_github_main.py"],
47
  "transport": "stdio",
48
  }
49
  }
mcpc_graph.py CHANGED
@@ -18,25 +18,30 @@ from pmcp.nodes.human_resume_node import HumanResumeNode
18
  from pmcp.models.state import PlanningState
19
 
20
 
21
- async def setup_graph():
22
- mcp_client_trello = MultiServerMCPClient(
 
23
  {
24
- "trello": {
25
  "command": "python",
26
- "args": [os.getenv("MCP_TRELLO_PATH")],
27
  "transport": "stdio",
28
  }
29
  }
30
  )
31
- mcp_client_github = MultiServerMCPClient(
 
 
32
  {
33
- "github": {
34
  "command": "python",
35
- "args": [os.getenv("MCP_GITHUB_PATH")],
36
  "transport": "stdio",
37
  }
38
  }
39
  )
 
 
40
 
41
  memory = MemorySaver()
42
 
@@ -52,6 +57,7 @@ async def setup_graph():
52
  base_url="https://api.studio.nebius.com/v1/",
53
  )
54
 
 
55
  trello_agent = TrelloAgent(
56
  tools=trello_tools,
57
  llm=llm,
 
18
  from pmcp.models.state import PlanningState
19
 
20
 
21
+ async def setup_graph(github_token: str, trello_api:str, trello_token:str):
22
+
23
+ mcp_client_github = MultiServerMCPClient(
24
  {
25
+ "github": {
26
  "command": "python",
27
+ "args": ["pmcp/mcp_server/github_server/mcp_github_main.py", "--api-key", github_token],
28
  "transport": "stdio",
29
  }
30
  }
31
  )
32
+
33
+
34
+ mcp_client_trello = MultiServerMCPClient(
35
  {
36
+ "trello": {
37
  "command": "python",
38
+ "args": ["pmcp/mcp_server/trello_server/mcp_trello_main.py", "--api-key", trello_api, "--token", trello_token],
39
  "transport": "stdio",
40
  }
41
  }
42
  )
43
+
44
+
45
 
46
  memory = MemorySaver()
47
 
 
57
  base_url="https://api.studio.nebius.com/v1/",
58
  )
59
 
60
+
61
  trello_agent = TrelloAgent(
62
  tools=trello_tools,
63
  llm=llm,
pmcp/mcp_server/__init__.py ADDED
File without changes
pmcp/mcp_server/github_server/connection_test.py CHANGED
@@ -1,14 +1,28 @@
 
 
1
  from fastmcp import Client
 
2
 
3
  async def main():
4
- # Connect via stdio to a local script
5
- async with Client("mcp_github_main.py") as client:
 
 
 
 
 
 
 
6
  tools = await client.list_tools()
7
- print(f"Available tools: {tools}")
8
- result = await client.call_tool("get_issues", {"owner":"jlowin", "repo":"fastmcp"})
9
- print(f"Result: {result}")
10
 
 
 
 
 
 
11
 
12
  if __name__ == "__main__":
13
- import asyncio
14
- asyncio.run(main())
 
 
1
+ # client_with_stdio.py
2
+ import asyncio
3
  from fastmcp import Client
4
+ from fastmcp.client.transports import PythonStdioTransport
5
 
6
  async def main():
7
+
8
+ transport = PythonStdioTransport(
9
+ python_cmd="python",
10
+ script_path="mcp_github_main.py",
11
+ args=["--api-key", "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"]
12
+ )
13
+
14
+
15
+ async with Client(transport) as client:
16
  tools = await client.list_tools()
17
+ print("Available tools:", tools)
 
 
18
 
19
+ result = await client.call_tool(
20
+ "get_issues",
21
+ {"owner": "jlowin", "repo": "fastmcp"}
22
+ )
23
+ print("Result:", result)
24
 
25
  if __name__ == "__main__":
26
+ asyncio.run(main())
27
+
28
+
pmcp/mcp_server/github_server/github.py CHANGED
@@ -1,25 +1,19 @@
1
- import os
2
-
3
- from dotenv import load_dotenv
4
-
5
  from pmcp.mcp_server.github_server.utils.github_api import GithubClient
6
 
7
 
8
- # Load environment variables
9
- load_dotenv()
10
 
11
- client = None
12
- # Initialize Github client and service
13
- try:
14
- api_key = os.getenv("GITHUB_API_KEY")
15
 
16
- if not api_key:
17
- raise ValueError(
18
- "GITHUB_API_KEY must be set in environment variables"
19
- )
20
- client = GithubClient(api_key=api_key)
21
- except Exception as e:
22
- raise
 
 
 
23
 
24
 
25
  # Add a prompt for common Github operations
 
 
 
 
 
1
  from pmcp.mcp_server.github_server.utils.github_api import GithubClient
2
 
3
 
 
 
4
 
5
+ github_client = None
 
 
 
6
 
7
+ def initialize_github_client(api_key: str = None) -> None:
8
+ try:
9
+ if not api_key:
10
+ raise ValueError(
11
+ "api_key required"
12
+ )
13
+ global github_client
14
+ github_client = GithubClient(api_key=api_key)
15
+ except Exception as e:
16
+ raise
17
 
18
 
19
  # Add a prompt for common Github operations
pmcp/mcp_server/github_server/mcp_github_main.py CHANGED
@@ -1,9 +1,10 @@
1
  import logging
2
 
3
- from dotenv import load_dotenv
4
  from mcp.server.fastmcp import FastMCP
5
 
6
- from pmcp.mcp_server.github_server.tools.tools import register_tools
 
7
 
8
  # Configure logging
9
  logging.basicConfig(
@@ -11,18 +12,22 @@ logging.basicConfig(
11
  )
12
  logger = logging.getLogger(__name__)
13
 
14
- # Load environment variables
15
- load_dotenv()
16
 
 
 
 
 
17
 
18
- # Initialize MCP server
19
- mcp = FastMCP("Github MCP Server")
20
 
21
- # Register tools
22
- register_tools(mcp)
23
 
 
 
 
 
24
 
25
- if __name__ == "__main__":
26
  try:
27
  logger.info("Starting Github MCP Server in Stdio...")
28
  mcp.run()
@@ -32,3 +37,6 @@ if __name__ == "__main__":
32
  except Exception as e:
33
  logger.error(f"Server error: {str(e)}")
34
  raise
 
 
 
 
1
  import logging
2
 
3
+ import argparse
4
  from mcp.server.fastmcp import FastMCP
5
 
6
+ from pmcp.mcp_server.github_server.github import initialize_github_client
7
+
8
 
9
  # Configure logging
10
  logging.basicConfig(
 
12
  )
13
  logger = logging.getLogger(__name__)
14
 
 
 
15
 
16
+ def parse_args():
17
+ parser = argparse.ArgumentParser(description="Avvia il Github MCP Server")
18
+ parser.add_argument("--api-key", type=str, required=True, help="API key per GitHub")
19
+ return parser.parse_args()
20
 
21
+ def main():
22
+ args = parse_args()
23
 
24
+ initialize_github_client(args.api_key)
 
25
 
26
+ mcp = FastMCP("Github MCP Server")
27
+ #import here because the client is not initialized yet
28
+ from pmcp.mcp_server.github_server.tools.tools import register_tools
29
+ register_tools(mcp)
30
 
 
31
  try:
32
  logger.info("Starting Github MCP Server in Stdio...")
33
  mcp.run()
 
37
  except Exception as e:
38
  logger.error(f"Server error: {str(e)}")
39
  raise
40
+
41
+ if __name__ == "__main__":
42
+ main()
pmcp/mcp_server/github_server/services/contents.py CHANGED
@@ -1,4 +1,4 @@
1
- from pmcp.mcp_server.github.utils.github_api import GithubClient
2
 
3
 
4
  class ContentService:
 
1
+ from pmcp.mcp_server.github_server.utils.github_api import GithubClient
2
 
3
 
4
  class ContentService:
pmcp/mcp_server/github_server/services/issues.py CHANGED
@@ -1,7 +1,7 @@
1
  """
2
  Service for managing GitHub issues in the MCP server.
3
  """
4
- from pmcp.mcp_server.github.utils.github_api import GithubClient
5
 
6
 
7
 
 
1
  """
2
  Service for managing GitHub issues in the MCP server.
3
  """
4
+ from pmcp.mcp_server.github_server.utils.github_api import GithubClient
5
 
6
 
7
 
pmcp/mcp_server/github_server/services/pull_requests.py CHANGED
@@ -1,4 +1,4 @@
1
- from pmcp.mcp_server.github.utils.github_api import GithubClient
2
 
3
 
4
  class PullRequestService:
 
1
+ from pmcp.mcp_server.github_server.utils.github_api import GithubClient
2
 
3
 
4
  class PullRequestService:
pmcp/mcp_server/github_server/services/repo_to_text.py CHANGED
@@ -1,7 +1,7 @@
1
  """
2
  Service for managing Github issues in MCP server.
3
  """
4
- from pmcp.mcp_server.github.utils.github_api import GithubClient
5
 
6
 
7
 
 
1
  """
2
  Service for managing Github issues in MCP server.
3
  """
4
+ from pmcp.mcp_server.github_server.utils.github_api import GithubClient
5
 
6
 
7
 
pmcp/mcp_server/github_server/tools/branches.py CHANGED
@@ -4,9 +4,9 @@ Branch listing tool.
4
  from typing import List, Dict
5
  from mcp.server.fastmcp import Context
6
  from pmcp.mcp_server.github_server.services.branches import BranchService
7
- from pmcp.mcp_server.github_server.github import client
8
 
9
- service = BranchService(client)
10
 
11
 
12
  async def list_branches(ctx: Context, owner: str, repo: str) -> Dict[str, List[str]]:
 
4
  from typing import List, Dict
5
  from mcp.server.fastmcp import Context
6
  from pmcp.mcp_server.github_server.services.branches import BranchService
7
+ from pmcp.mcp_server.github_server.github import github_client
8
 
9
+ service = BranchService(github_client)
10
 
11
 
12
  async def list_branches(ctx: Context, owner: str, repo: str) -> Dict[str, List[str]]:
pmcp/mcp_server/github_server/tools/contents.py CHANGED
@@ -5,9 +5,9 @@ import base64
5
  from typing import List, Dict
6
  from mcp.server.fastmcp import Context
7
  from pmcp.mcp_server.github_server.services.contents import ContentService
8
- from pmcp.mcp_server.github_server.github import client
9
 
10
- service = ContentService(client)
11
 
12
 
13
  async def get_recent_commits(
 
5
  from typing import List, Dict
6
  from mcp.server.fastmcp import Context
7
  from pmcp.mcp_server.github_server.services.contents import ContentService
8
+ from pmcp.mcp_server.github_server.github import github_client
9
 
10
+ service = ContentService(github_client)
11
 
12
 
13
  async def get_recent_commits(
pmcp/mcp_server/github_server/tools/issues.py CHANGED
@@ -5,10 +5,10 @@ from typing import List, Dict, Any
5
  from mcp.server.fastmcp import Context
6
 
7
  from pmcp.mcp_server.github_server.services.issues import IssueService
8
- from pmcp.mcp_server.github_server.github import client
9
 
10
 
11
- service = IssueService(client)
12
 
13
 
14
  # ───────────────────────────────────────────────────────────────────────── #
 
5
  from mcp.server.fastmcp import Context
6
 
7
  from pmcp.mcp_server.github_server.services.issues import IssueService
8
+ from pmcp.mcp_server.github_server.github import github_client
9
 
10
 
11
+ service = IssueService(github_client)
12
 
13
 
14
  # ───────────────────────────────────────────────────────────────────────── #
pmcp/mcp_server/github_server/tools/pull_requests.py CHANGED
@@ -4,9 +4,9 @@ Pull-request utilities (read-only).
4
  from typing import List, Dict
5
  from mcp.server.fastmcp import Context
6
  from pmcp.mcp_server.github_server.services.pull_requests import PullRequestService
7
- from pmcp.mcp_server.github_server.github import client
8
 
9
- service = PullRequestService(client)
10
 
11
 
12
  async def get_pull_requests(
 
4
  from typing import List, Dict
5
  from mcp.server.fastmcp import Context
6
  from pmcp.mcp_server.github_server.services.pull_requests import PullRequestService
7
+ from pmcp.mcp_server.github_server.github import github_client
8
 
9
+ service = PullRequestService(github_client)
10
 
11
 
12
  async def get_pull_requests(
pmcp/mcp_server/github_server/tools/repo.py CHANGED
@@ -3,10 +3,10 @@ Repository-level stats tool.
3
  """
4
  from mcp.server.fastmcp import Context
5
  from pmcp.mcp_server.github_server.services.repo import RepoService
6
- from pmcp.mcp_server.github_server.github import client
7
 
8
 
9
- service = RepoService(client)
10
 
11
 
12
  async def get_repo_stats(ctx: Context, owner: str, repo: str):
 
3
  """
4
  from mcp.server.fastmcp import Context
5
  from pmcp.mcp_server.github_server.services.repo import RepoService
6
+ from pmcp.mcp_server.github_server.github import github_client
7
 
8
 
9
+ service = RepoService(github_client)
10
 
11
 
12
  async def get_repo_stats(ctx: Context, owner: str, repo: str):
pmcp/mcp_server/github_server/tools/repo_to_text.py CHANGED
@@ -3,15 +3,15 @@ This module contains tools for managing Github.
3
  """
4
 
5
  from pmcp.mcp_server.github_server.services.repo_to_text import RepoToTextService
6
- from pmcp.mcp_server.github_server.github import client
7
 
8
  from mcp.server.fastmcp import Context
9
 
10
 
11
- service = RepoToTextService(client)
12
 
13
  async def get_repo_to_text(ctx: Context, repo: str) -> str:
14
- """Retrieves the content of a repository as text.
15
 
16
  Args:
17
  repo (str): The name of the repository.
 
3
  """
4
 
5
  from pmcp.mcp_server.github_server.services.repo_to_text import RepoToTextService
6
+ from pmcp.mcp_server.github_server.github import github_client
7
 
8
  from mcp.server.fastmcp import Context
9
 
10
 
11
+ service = RepoToTextService(github_client)
12
 
13
  async def get_repo_to_text(ctx: Context, repo: str) -> str:
14
+ """Retrieves the repo structure and the repo content as text.
15
 
16
  Args:
17
  repo (str): The name of the repository.
pmcp/mcp_server/trello_server/mcp_trello_main.py CHANGED
@@ -1,9 +1,8 @@
1
  import logging
2
-
3
- from dotenv import load_dotenv
4
  from mcp.server.fastmcp import FastMCP
5
 
6
- from pmcp.mcp_server.trello_server.tools.tools import register_tools
7
 
8
  # Configure logging
9
  logging.basicConfig(
@@ -11,19 +10,25 @@ logging.basicConfig(
11
  )
12
  logger = logging.getLogger(__name__)
13
 
14
- # Load environment variables
15
- load_dotenv()
16
 
 
 
 
 
 
17
 
18
- # Initialize MCP server
19
- mcp = FastMCP("Trello MCP Server")
20
 
21
- # Register tools
22
- register_tools(mcp)
23
 
 
24
 
 
 
 
 
 
25
 
26
- if __name__ == "__main__":
27
  try:
28
  logger.info("Starting Trello MCP Server in Stdio...")
29
  mcp.run()
@@ -33,3 +38,7 @@ if __name__ == "__main__":
33
  except Exception as e:
34
  logger.error(f"Server error: {str(e)}")
35
  raise
 
 
 
 
 
1
  import logging
2
+ import argparse
 
3
  from mcp.server.fastmcp import FastMCP
4
 
5
+ from pmcp.mcp_server.trello_server.trello import initialize_trello_client
6
 
7
  # Configure logging
8
  logging.basicConfig(
 
10
  )
11
  logger = logging.getLogger(__name__)
12
 
 
 
13
 
14
+ def parse_args():
15
+ parser = argparse.ArgumentParser(description="Avvia il Trello MCP Server")
16
+ parser.add_argument("--api-key", type=str, required=True, help="API key per Trello")
17
+ parser.add_argument("--token", type=str, required=True, help="Token per Trello")
18
+ return parser.parse_args()
19
 
 
 
20
 
21
+ def main():
22
+ args = parse_args()
23
 
24
+ initialize_trello_client(args.api_key, args.token)
25
 
26
+ mcp = FastMCP("Trello MCP Server")
27
+ # import here because the client is not initialized yet
28
+ from pmcp.mcp_server.trello_server.tools.tools import register_tools
29
+
30
+ register_tools(mcp)
31
 
 
32
  try:
33
  logger.info("Starting Trello MCP Server in Stdio...")
34
  mcp.run()
 
38
  except Exception as e:
39
  logger.error(f"Server error: {str(e)}")
40
  raise
41
+
42
+
43
+ if __name__ == "__main__":
44
+ main()
pmcp/mcp_server/trello_server/tools/board.py CHANGED
@@ -9,11 +9,11 @@ from mcp.server.fastmcp import Context
9
 
10
  from pmcp.mcp_server.trello_server.models import TrelloBoard, TrelloLabel
11
  from pmcp.mcp_server.trello_server.services.board import BoardService
12
- from pmcp.mcp_server.trello_server.trello import client
13
 
14
 
15
 
16
- service = BoardService(client)
17
 
18
 
19
  async def get_board(ctx: Context, board_id: str) -> TrelloBoard:
 
9
 
10
  from pmcp.mcp_server.trello_server.models import TrelloBoard, TrelloLabel
11
  from pmcp.mcp_server.trello_server.services.board import BoardService
12
+ from pmcp.mcp_server.trello_server.trello import trello_client
13
 
14
 
15
 
16
+ service = BoardService(trello_client)
17
 
18
 
19
  async def get_board(ctx: Context, board_id: str) -> TrelloBoard:
pmcp/mcp_server/trello_server/tools/card.py CHANGED
@@ -9,11 +9,11 @@ from mcp.server.fastmcp import Context
9
 
10
  from pmcp.mcp_server.trello_server.models import TrelloCard
11
  from pmcp.mcp_server.trello_server.services.card import CardService
12
- from pmcp.mcp_server.trello_server.trello import client
13
  from pmcp.mcp_server.trello_server.dtos.update_card import UpdateCardPayload
14
 
15
 
16
- service = CardService(client)
17
 
18
 
19
  async def get_card(ctx: Context, card_id: str) -> TrelloCard:
 
9
 
10
  from pmcp.mcp_server.trello_server.models import TrelloCard
11
  from pmcp.mcp_server.trello_server.services.card import CardService
12
+ from pmcp.mcp_server.trello_server.trello import trello_client
13
  from pmcp.mcp_server.trello_server.dtos.update_card import UpdateCardPayload
14
 
15
 
16
+ service = CardService(trello_client)
17
 
18
 
19
  async def get_card(ctx: Context, card_id: str) -> TrelloCard:
pmcp/mcp_server/trello_server/tools/checklist.py CHANGED
@@ -6,9 +6,9 @@ import logging
6
  from typing import Dict, List, Optional
7
 
8
  from pmcp.mcp_server.trello_server.services.checklist import ChecklistService
9
- from pmcp.mcp_server.trello_server.trello import client
10
 
11
- service = ChecklistService(client)
12
 
13
 
14
  async def get_checklist(checklist_id: str) -> Dict:
 
6
  from typing import Dict, List, Optional
7
 
8
  from pmcp.mcp_server.trello_server.services.checklist import ChecklistService
9
+ from pmcp.mcp_server.trello_server.trello import trello_client
10
 
11
+ service = ChecklistService(trello_client)
12
 
13
 
14
  async def get_checklist(checklist_id: str) -> Dict:
pmcp/mcp_server/trello_server/tools/list.py CHANGED
@@ -9,11 +9,11 @@ from mcp.server.fastmcp import Context
9
 
10
  from pmcp.mcp_server.trello_server.models import TrelloList
11
  from pmcp.mcp_server.trello_server.services.list import ListService
12
- from pmcp.mcp_server.trello_server.trello import client
13
 
14
 
15
 
16
- service = ListService(client)
17
 
18
 
19
  # List Tools
 
9
 
10
  from pmcp.mcp_server.trello_server.models import TrelloList
11
  from pmcp.mcp_server.trello_server.services.list import ListService
12
+ from pmcp.mcp_server.trello_server.trello import trello_client
13
 
14
 
15
 
16
+ service = ListService(trello_client)
17
 
18
 
19
  # List Tools
pmcp/mcp_server/trello_server/trello.py CHANGED
@@ -1,27 +1,22 @@
1
- import logging
2
  import os
3
 
4
- from dotenv import load_dotenv
5
-
6
  from pmcp.mcp_server.trello_server.utils.trello_api import TrelloClient
7
 
8
 
9
- # Load environment variables
10
- load_dotenv()
11
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- # Initialize Trello client and service
14
- try:
15
- api_key = os.getenv("TRELLO_API_KEY")
16
- token = os.getenv("TRELLO_TOKEN")
17
- if not api_key or not token:
18
- raise ValueError(
19
- "TRELLO_API_KEY and TRELLO_TOKEN must be set in environment variables"
20
- )
21
- client = TrelloClient(api_key=api_key, token=token)
22
-
23
- except Exception as e:
24
- raise
25
 
26
 
27
  # Add a prompt for common Trello operations
 
 
1
  import os
2
 
 
 
3
  from pmcp.mcp_server.trello_server.utils.trello_api import TrelloClient
4
 
5
 
 
 
6
 
7
+ trello_client = None
8
+
9
+ def initialize_trello_client(api_key: str = None, token:str = None) -> None:
10
+ try:
11
+ if not api_key:
12
+ raise ValueError(
13
+ "api_key and tokne required"
14
+ )
15
+ global trello_client
16
+ trello_client = TrelloClient(api_key=api_key, token=token)
17
+ except Exception as e:
18
+ raise
19
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
 
22
  # Add a prompt for common Trello operations