@hapticpaper/mcp-server 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +26 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -96,12 +96,36 @@ ${widgetJs}
|
|
|
96
96
|
registerAllResources(server, client);
|
|
97
97
|
return server;
|
|
98
98
|
}
|
|
99
|
-
//
|
|
99
|
+
// Helper to run interactive OAuth flow
|
|
100
|
+
const runOAuthFlow = async () => {
|
|
101
|
+
console.error('No valid token found. Starting authentication...');
|
|
102
|
+
const auth = new MCPOAuthHandler({
|
|
103
|
+
clientId: 'mcp-client',
|
|
104
|
+
authorizationUrl: process.env.AUTH_URL || 'https://hapticpaper.com/oauth/authorize',
|
|
105
|
+
tokenUrl: process.env.TOKEN_URL || 'https://hapticpaper.com/api/v1/oauth/token',
|
|
106
|
+
redirectUri: 'http://localhost:8765/callback',
|
|
107
|
+
scopes: ['tasks:read', 'tasks:write', 'workers:read']
|
|
108
|
+
});
|
|
109
|
+
const tokens = await auth.authenticate();
|
|
110
|
+
await tokenManager.saveTokens(tokens);
|
|
111
|
+
console.error('Authentication successful!');
|
|
112
|
+
return tokens.access_token;
|
|
113
|
+
};
|
|
114
|
+
// Initialize Client with auto-auth tokenProvider
|
|
100
115
|
const client = new HireHumanClient({
|
|
101
116
|
baseUrl: process.env.API_URL || 'https://hapticpaper.com/api/v1',
|
|
102
117
|
tokenProvider: async () => {
|
|
103
118
|
const tokens = await tokenManager.loadTokens();
|
|
104
|
-
|
|
119
|
+
if (tokens?.access_token) {
|
|
120
|
+
// Check if token is expired (with 5 min buffer)
|
|
121
|
+
if (tokens.expires_at && tokens.expires_at < Date.now() + 5 * 60 * 1000) {
|
|
122
|
+
console.error('Token expired, re-authenticating...');
|
|
123
|
+
return runOAuthFlow();
|
|
124
|
+
}
|
|
125
|
+
return tokens.access_token;
|
|
126
|
+
}
|
|
127
|
+
// No token - auto-trigger OAuth
|
|
128
|
+
return runOAuthFlow();
|
|
105
129
|
}
|
|
106
130
|
});
|
|
107
131
|
// Transport
|