Skip to content

Commit 8ba7d09

Browse files
committed
refactor: 💡 remove unnecessary codes and comments
1 parent 671576b commit 8ba7d09

File tree

6 files changed

+12
-53
lines changed

6 files changed

+12
-53
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ uv sync
9696
3. **AIチャットやツールパネルからAPIを呼び出し**
9797

9898
- AIチャット上で `user_get_info``posts_get_list` などのMCPツールを呼び出すことで、esa.io APIと連携した操作が可能です。
99-
- `mcp-esa-server を使って記事の作成をお願いします` などとチャット上で書き込むことで利用できます。
99+
- `mcp-esa-serverを使って記事の作成をお願いします` などとチャット上で書き込むことで利用できます。
100100

101101
## ライセンス (License)
102102

@@ -107,7 +107,7 @@ uv sync
107107

108108
このプロジェクトの一部では、以下のMIT Licenseで公開されているコードを参照しています。
109109

110-
- **[参照元プロジェクト名]**
110+
- **esa-mcp-server**
111111
- GitHubリポジトリ: [https://github.com/masseater/esa-mcp-server]
112112
- ライセンス: MIT License
113113

docs/mcp_esa_development_summary.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
## サーバー設計・技術スタック
88

9-
- **FastAPI**: Webフレームワーク
109
- **FastMCP**: MCPプロトコル実装
11-
- **aiohttp**: 非同期HTTPクライアント
1210
- **pytest/ruff**: テスト・フォーマット
1311

1412
## 主要機能

docs/mcp_esa_server_usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ESA_TEAM_NAME=your_team_name
3434
- **引数:** `post_number`(記事番号)
3535
- **戻り値:** 記事詳細情報を含む辞書(例: `{ "post": {...} }`
3636

37-
### posts_create(name: str, body_md: str, tags: list[str] | None = None, category: str | None = None, wip: bool | None = True, message: str | None = None)
37+
### posts_create(name: str, body_md: str, tags: list[str] = [], category: str = "", wip: bool = True, message: str = "")
3838
- **説明:** 新しい記事を作成します。
3939
- **引数:** `name`, `body_md`, `tags`, `category`, `wip`, `message`
4040
- **戻り値:** 作成された記事の情報(例: `{ "post": {...} }`

esa_client.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,6 @@ def delete_post(self, post_number: int):
122122
try:
123123
client = EsaClient()
124124
logger.info(f"EsaClient initialized for team: {client.team_name}")
125-
# Add a simple test request here later if needed
126-
print("Attempting to get user info...")
127-
user_info = client.get_user()
128-
print("Successfully retrieved user info:")
129-
print(user_info)
130125
except ValueError as e:
131126
logger.error(f"Initialization failed: {e}")
132127
except requests.exceptions.RequestException as e:

main.py

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@
33
from typing import Annotated, Any
44

55
from dotenv import load_dotenv
6-
7-
# Remove FastAPI and HTTPException imports as they are no longer directly used
8-
# from fastapi import FastAPI, HTTPException
96
from mcp.server.fastmcp import FastMCP
107
from pydantic import Field
118

12-
# Use direct import as files are now in the same directory
13-
# from src.esa_client import EsaClient
149
from esa_client import EsaClient
1510

1611
# Load environment variables from .env file
@@ -20,17 +15,13 @@
2015
logging.basicConfig(level=logging.INFO)
2116
logger = logging.getLogger(__name__)
2217

23-
# Remove FastAPI app initialization
24-
# app = FastAPI()
25-
2618
# Create MCP instance
2719
mcp = FastMCP("esa-mcp-server")
2820

2921
# Get environment variables
3022
esa_token = os.getenv("ESA_TOKEN")
3123
esa_team_name = os.getenv("ESA_TEAM_NAME")
3224

33-
# 追加: 環境変数の値をログに出力
3425
logger.info("Attempting to initialize EsaClient.")
3526
logger.info(f"ESA_TOKEN from env: {esa_token}")
3627
logger.info(f"ESA_TEAM_NAME from env: {esa_team_name}")
@@ -41,8 +32,6 @@
4132
esa_client = None
4233
else:
4334
try:
44-
# Initialize EsaClient without arguments, let it read env vars internally
45-
# esa_client = EsaClient(api_token=esa_token, team_name=esa_team_name)
4635
esa_client = EsaClient()
4736
logger.info("EsaClient initialized successfully.")
4837
except ValueError as e: # Catch potential ValueError from EsaClient init
@@ -143,32 +132,27 @@ def posts_create(
143132
"""
144133
if esa_client is None:
145134
logger.error("EsaClient is not initialized. Cannot create post.")
146-
raise RuntimeError("EsaClient not initialized") # Changed from HTTPException
135+
raise RuntimeError("EsaClient not initialized")
147136
try:
148137
logger.info(f"Creating post with name: {name}")
149138

150-
# MODIFIED SECTION: Handle empty string category as None
151-
# This ensures that if category is an empty string (default or explicitly passed),
152-
# it's treated as 'no category' and will be removed from the payload if None.
153-
effective_category = category if category else None
154-
155139
payload = {
156140
"name": name,
157141
"body_md": body_md,
158142
"tags": tags or [],
159-
"category": effective_category,
143+
"category": category,
160144
"wip": wip,
161145
"message": message,
162146
}
163147
# Remove None values from payload
164148
payload = {k: v for k, v in payload.items() if v is not None}
165149

166-
new_post = esa_client.create_post(payload=payload) # Removed await
150+
new_post = esa_client.create_post(payload=payload)
167151
logger.info(f"Successfully created post: {new_post.get('url')}")
168152
return new_post
169153
except Exception as e:
170154
logger.error(f"Error creating post: {e}", exc_info=True)
171-
raise RuntimeError(f"Error creating post: {e}") from e # Changed from HTTPException
155+
raise RuntimeError(f"Error creating post: {e}") from e
172156

173157

174158
@mcp.tool()
@@ -194,7 +178,7 @@ def posts_update(
194178
"""
195179
if esa_client is None:
196180
logger.error("EsaClient is not initialized. Cannot update post.")
197-
raise RuntimeError("EsaClient not initialized") # Changed from HTTPException
181+
raise RuntimeError("EsaClient not initialized")
198182
try:
199183
logger.info(f"Updating post number: {post_number}")
200184
payload = {
@@ -211,15 +195,14 @@ def posts_update(
211195
if not payload:
212196
logger.warning(f"No update parameters provided for post {post_number}.")
213197
# Consider returning current post details or raising a more specific error
214-
# For now, returning a message indicating no action was taken.
215198
return {"message": f"No update parameters provided for post {post_number}. Nothing changed."}
216199

217200
updated_post = esa_client.update_post(post_number=post_number, payload=payload)
218201
logger.info(f"Successfully updated post: {updated_post.get('url')}")
219202
return updated_post
220203
except Exception as e:
221204
logger.error(f"Error updating post {post_number}: {e}", exc_info=True)
222-
raise RuntimeError(f"Error updating post: {e}") from e # Changed from HTTPException
205+
raise RuntimeError(f"Error updating post: {e}") from e
223206

224207

225208
@mcp.tool()
@@ -231,34 +214,18 @@ def posts_delete(post_number: int) -> dict[str, Any]:
231214
"""
232215
if esa_client is None:
233216
logger.error("EsaClient is not initialized. Cannot delete post.")
234-
raise RuntimeError("EsaClient not initialized") # Changed from HTTPException
217+
raise RuntimeError("EsaClient not initialized")
235218
try:
236-
logger.info(f"Deleting post number: {post_number}")
237-
esa_client.delete_post(post_number) # Removed await
219+
esa_client.delete_post(post_number)
238220
logger.info(f"Successfully deleted post {post_number}.")
239221
# Return empty dict upon successful deletion as per esa.io API
240-
# (204 No Content)
241222
return {}
242223
except Exception as e:
243224
logger.error(f"Error deleting post {post_number}: {e}", exc_info=True)
244-
raise RuntimeError(f"Error deleting post: {e}") from e # Changed from HTTPException
245-
246-
247-
# Mount MCP router using sse_app
248-
# app.include_router(mcp.router)
249-
# app.mount("/mcp", app=mcp.sse_app())
250-
# @app.get("/")
251-
# async def root():
252-
# return {"message": "MCP Server for esa.io is running"}
253-
225+
raise RuntimeError(f"Error deleting post: {e}") from e
254226

255-
# TODO: Add MCP tools based on EsaClient methods
256-
# TODO: Add error handling for EsaClient initialization failures
257227

258228
# Use mcp.run() to start the server when script is executed directly
259229
if __name__ == "__main__":
260-
# Remove uvicorn import and run
261-
# import uvicorn
262-
# uvicorn.run(app, host="0.0.0.0", port=8000)
263230
logger.info("Starting MCP server...")
264231
mcp.run()

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ authors = [
66
{name = "Naoki Numaguchi", email = "[email protected]"},
77
]
88
dependencies = [
9-
# "fastapi", # Removed fastapi as it's no longer directly used
109
"requests",
1110
"python-dotenv",
1211
"mcp[cli]>=1.7.1",

0 commit comments

Comments
 (0)