| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- class BindAuthCodeTool:
- name = 'bind_auth_code'
- requires_session = False
- def __init__(self, auth_client=None):
- self.auth_client = auth_client
- def metadata(self):
- return {
- 'name': self.name,
- 'description': 'Bind a one-time Workbuddy auth code and create the local MCP session.',
- 'input_schema': {
- 'type': 'object',
- 'properties': {
- 'auth_code': {
- 'type': 'string',
- 'description': 'One-time auth code copied from the FMS backend.',
- },
- },
- 'required': ['auth_code'],
- },
- }
- def call(self, auth_code, request_id=''):
- if self.auth_client is None:
- raise RuntimeError('auth client is required for bind_auth_code')
- auth_code = str(auth_code or '').strip()
- if not auth_code:
- raise ValueError('auth_code is required')
- response = self.auth_client.exchange(auth_code)
- if (response.get('code') or '') != 'MCP_0000':
- raise RuntimeError(response.get('msg') or 'auth_code bind failed')
- data = response.get('data') or {}
- return {
- 'code': 'MCP_0000',
- 'msg': 'success',
- 'data': {
- 'status': 'bound',
- 'summary': '绑定成功,可以继续使用 query_order 查询订单。',
- 'expire_time': data.get('expire_time'),
- 'tips': [
- '后续工具调用会自动使用本机已保存的 MCP 会话。',
- '如果授权失效,请回后台重新获取 Workbuddy 授权码。',
- ],
- },
- 'meta': {
- 'request_id': request_id,
- },
- }
|