Skip to content

Commit ad87b14

Browse files
committed
sharepoint サイトの情報を取得するコマンドを追加
1 parent 418d40f commit ad87b14

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

docs/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ uv run python scripts/microsoft_graphs.py get-access-token
128128
uv run python scripts/microsoft_graphs.py get-my-profile \
129129
--access-token $ACCESS_TOKEN \
130130
--expires-on $EXPIRES_ON
131+
132+
# Get SharePoint sites
133+
uv run python scripts/microsoft_graphs.py get-sites \
134+
--site-id $SITE_ID \
135+
--access-token $ACCESS_TOKEN \
136+
--expires-on $EXPIRES_ON
131137
```
132138

133139
## MCP

scripts/microsoft_graphs.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,44 @@ def get_access_token():
115115
console.print(f"[bold red]エラー[/bold red]: {str(e)}")
116116

117117

118+
@app.command()
119+
def get_sites(
120+
site_id: str | None = typer.Option(None, "--site-id", "-s", help="取得するサイトの ID(省略時は全サイト)"),
121+
access_token: str | None = typer.Option(None, "--access-token", "-a", help="アクセストークンを指定して認証する"),
122+
expires_on: int | None = typer.Option(
123+
None, "--expires-on", "-e", help="アクセストークンの有効期限を指定(Unix時間)"
124+
),
125+
):
126+
"""SharePoint サイトの情報を取得する"""
127+
console.print("[bold green]SharePoint サイト[/bold green]の情報を取得します")
128+
129+
async def _get_sites():
130+
try:
131+
client = get_graph_client(access_token=access_token, expires_on=expires_on)
132+
133+
if site_id:
134+
site = await client.sites.by_site_id(site_id).get()
135+
sites = [site]
136+
else:
137+
sites_response = await client.sites.get()
138+
sites = sites_response.value if sites_response.value else []
139+
140+
# テーブルで表示
141+
table = Table(title="SharePoint サイト")
142+
table.add_column("ID", style="cyan")
143+
table.add_column("名前", style="green")
144+
table.add_column("URL", style="blue")
145+
146+
for site in sites:
147+
table.add_row(site.id, site.name, site.web_url)
148+
149+
console.print(table)
150+
151+
except Exception as e:
152+
console.print(f"[bold red]エラー[/bold red]: {str(e)}")
153+
154+
asyncio.run(_get_sites())
155+
156+
118157
if __name__ == "__main__":
119158
app()

0 commit comments

Comments
 (0)