Skip to main content
Glama

Slack MCP Server

by hyunol7
main.py4.9 kB
#!/usr/bin/env python3 """ Slack MCP 테스트 스크립트 5_강의장-python 채널에 메시지를 보내는 테스트 """ import os from slack_api import SlackClient from dotenv import load_dotenv # 환경 변수 로드 load_dotenv() # 테스트용 상수 TEST_CHANNEL_ID = "채널 ID" TEST_CHANNEL_NAME = "5_강의장" TEAM_ID = "_" def test_specific_channel(): """메시지 전송 테스트""" try: # Slack 클라이언트 초기화 client = SlackClient() print(" Slack 클라이언트 초기화 완료") # 1. 채널 ID로 메시지 전송 테스트 print(f"\n 채널 ID ({TEST_CHANNEL_ID})로 메시지 전송 테스트...") result1 = client.send_message( channel=TEST_CHANNEL_ID, text="테스트 test" ) if result1["success"]: print(f" 성공: {result1['message']}") print(f" 채널: {result1['channel']}") print(f" 타임스탬프: {result1['timestamp']}") else: print(f" 실패: {result1['error']}") return False # 3. 채널 히스토리 조회 테스트 print(f"\n 채널 히스토리 조회 테스트...") history_result = client.get_channel_history(TEST_CHANNEL_ID, limit=5) if history_result["success"]: print(f"{history_result['message']}") print("최근 메시지:") for i, msg in enumerate(history_result["messages"][:3], 1): user_name = msg["user"]["real_name"] or msg["user"]["name"] text_preview = msg["text"][:50] + "..." if len(msg["text"]) > 50 else msg["text"] print(f" {i}. {user_name}: {text_preview}") else: print(f"히스토리 조회 실패: {history_result['error']}") # 4. 모든 채널 목록에서 우리 채널 찾기 print(f"\n 채널 목록에서 '{TEST_CHANNEL_NAME}' 찾기...") channels_result = client.get_channels() if channels_result["success"]: target_channel = None for channel in channels_result["channels"]: if channel["id"] == TEST_CHANNEL_ID or channel["name"] == TEST_CHANNEL_NAME: target_channel = channel break if target_channel: print(f"채널을 찾기 완료") print(f"이름: #{target_channel['name']}") print(f"ID: {target_channel['id']}") print(f"멤버 수: {target_channel['member_count']}") print(f"비공개: {target_channel['is_private']}") print(f"멤버 여부: {target_channel['is_member']}") else: print(f"해당 채널을 찾을 수 없습니다.") else: print(f"채널 목록 조회 실패: {channels_result['error']}") print("테스트 완료") print("=" * 60) return True except Exception as e: print(f" 테스트 중 오류 발생: {e}") return False def test_all_functions(): """모든 기능 간단 테스트""" print("전체 기능 테스트") print("-" * 40) try: client = SlackClient() # 사용자 목록 조회 users_result = client.get_users() if users_result["success"]: print(f"사용자 조회 성공: {users_result['total_count']}명") else: print(f"사용자 조회 실패: {users_result['error']}") # 채널 목록 조회 channels_result = client.get_channels() if channels_result["success"]: print(f"채널 조회 성공: {channels_result['total_count']}개") else: print(f"채널 조회 실패: {channels_result['error']}") print("기본 기능 테스트 완료") except Exception as e: print(f"기능 테스트 오류: {e}") if __name__ == "__main__": # 환경 변수 체크 if not os.getenv("SLACK_BOT_TOKEN"): print("오류: SLACK_BOT_TOKEN 환경 변수가 설정되지 않았습니다.") print(".env 파일을 생성하고 다음과 같이 설정해주세요:") print(" SLACK_BOT_TOKEN=xoxb-your-token-here") print(f" TEST_CHANNEL_ID={TEST_CHANNEL_ID}") print(f" TEST_CHANNEL_NAME={TEST_CHANNEL_NAME}") print(f" TEAM_ID={TEAM_ID}") exit(1) print("Slack MCP 테스트 시작") print(f"대상 채널: #{TEST_CHANNEL_NAME} ({TEST_CHANNEL_ID})") print(f"팀 ID: {TEAM_ID}") # 메인 테스트 실행 success = test_specific_channel() if success: # 추가 기능 테스트 test_all_functions() print("\n🏁 테스트 종료")

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hyunol7/slack-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server