-
Notifications
You must be signed in to change notification settings - Fork 460
Expand file tree
/
Copy pathpost.py
More file actions
85 lines (70 loc) · 3.01 KB
/
Copy pathpost.py
File metadata and controls
85 lines (70 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""LinkedIn feed post engagement tools."""
import logging
from typing import Annotated, Any
from fastmcp import Context, FastMCP
from pydantic import Field
from linkedin_mcp_server.config.schema import DEFAULT_TOOL_TIMEOUT_SECONDS
from linkedin_mcp_server.core.exceptions import AuthenticationError
from linkedin_mcp_server.dependencies import get_ready_extractor, handle_auth_error
from linkedin_mcp_server.error_handler import raise_tool_error
logger = logging.getLogger(__name__)
def register_post_tools(
mcp: FastMCP, *, tool_timeout: float = DEFAULT_TOOL_TIMEOUT_SECONDS
) -> None:
"""Register feed-post engagement tools with the MCP server."""
@mcp.tool(
timeout=tool_timeout,
title="Comment on Post",
annotations={"destructiveHint": True, "openWorldHint": True},
tags={"feed", "actions"},
exclude_args=["extractor"],
)
async def comment_on_post(
post_url: str,
comment_text: Annotated[str, Field(min_length=1, max_length=1500)],
confirm_post: bool,
ctx: Context,
extractor: Any | None = None,
) -> dict[str, Any]:
"""
Post a top-level comment on a LinkedIn feed post.
This is a write operation when confirm_post is True. With
confirm_post=False the composer is located but no comment is
submitted, returning status="confirmation_required" — useful for
dry-run pre-flight checks before issuing the real call.
Args:
post_url: A feed post URL or activity reference. Accepts the
full /feed/update/urn:li:activity:{id}/ URL, the
/posts/<slug>-activity-{id}-<sig>/ permalink, a bare
urn:li:activity:{id} URN, or the bare numeric id.
comment_text: The comment body (1-1500 characters, plain text).
confirm_post: Must be True to actually submit the comment.
ctx: FastMCP context for progress reporting.
Returns:
Dict with url, status, message, posted, comment_visible.
"""
try:
extractor = extractor or await get_ready_extractor(
ctx, tool_name="comment_on_post"
)
logger.info(
"Posting comment on %s (confirm_post=%s, length=%d)",
post_url,
confirm_post,
len(comment_text),
)
await ctx.report_progress(progress=0, total=100, message="Posting comment")
result = await extractor.post_comment(
post_url,
comment_text,
confirm_post=confirm_post,
)
await ctx.report_progress(progress=100, total=100, message="Complete")
return result
except AuthenticationError as e:
try:
await handle_auth_error(e, ctx)
except Exception as relogin_exc:
raise_tool_error(relogin_exc, "comment_on_post")
except Exception as e:
raise_tool_error(e, "comment_on_post") # NoReturn